Question

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?

Was it helpful?

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.

OTHER TIPS

Binary logs used mostly for replication purposes and they do not allow to store any side information except data changes.

If you want to store viewable logs (because binary logs was designed in that way that it can used only mysql) you will need to have additional table to store: data from primary table + user + time.

Also you may take a look on Query Log

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top