mysqlsqldatabasebinary-log

Does MySQL binary log support logging Uid's?


I would like to know if it's possible using MySQL Binary Log to record Uid's (usernames) of the users who make modifications to the DB.

This is necessary for the audit purpose.

Is that possible?


Solution

  • That's not what the binary log is for - the binary log keeps a record of all changes made to a database, usually for the purposes of replication and recovery.

    A possible alternative might be the general query log, I believe that includes the username in some way.

    This is all assuming you're talking about actual connection usernames, not some arbitrary "user" in your application.

    Here's an example I just pulled from one of my logs:

    111130 13:46:50   130 Connect   myusername@localhost on
                      130 Init DB   mydatabase
                      130 Query     SELECT somefields FROM sometable
                      130 Query     SELECT somefields FROM sometable
                      130 Quit
    

    As you can see, you get the connection username, and then anything with that connection ID (in this case 130) is by that user on that connection.