Is there a way to identify who created the MySQL connection?

For example: in file a.php $conn = mysqli_connect($dbhost, $dbuser, $dbpwd, null, $port, $socket); I would like to know that this connection was initialized from a.php

I switched on the logger but all it told me that the connection was made but not who initialized it. Connect root@localhost on using Socket

  • Who has the root password?
    – Rick James
    Jun 17, 2019 at 16:25

1 Answer 1


Who has the root password? If there are multiple admins with root permissions, change them to non "root" user names, but with ALL PRIVILEGES. Then you can distinguish them in the general log.

"Socket" implies the same machine; nothing provides what program.

I recommend you add comments to every query, perhaps with the filename and line number (__LINE__).

  • I would like to know which file or from where the connection was made? Not which user made the connection. Like in the above example, I would like to know that a.php created the connection. Jun 18, 2019 at 6:40
  • @AnirudhSridhar - I added to my Answer.
    – Rick James
    Jun 18, 2019 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.