views:

144

answers:

2

Is it possible to find out all the command executed against a database in a given timeframe? For example, I would like to know who executed insert command on a database table in the last 24 hours.

Any help would be greatly appreciated.

Thanks.

A: 

http://dev.mysql.com/doc/refman/5.0/en/binary-log.html Binary log might help a bit.

Ilya Biryukov
+1  A: 

For queries which change data, you can check the binary log. However, I don't think this'll get you the user:

$ mysqlbinlog /var/log/mysql/mysql-bin.000145
…
# at 3178
#090805  6:25:15 server id 1  end_log_pos 3373  Query   thread_id=2170317       exec_time=0     error_code=0
SET TIMESTAMP=1249467915/*!*/;
UPDATE phpbb3_topics
                SET topic_views = topic_views + 1, topic_last_view_time = 1249467915
                WHERE topic_id = 95847/*!*/;
# at 3373
…

To get the user, you'll need to set up triggers on the tables and use those triggers to store an audit log in another table.

If you need to all queries—selects included—there is also the general query log but that is not normally on due to performance impacts and disk requirements.

derobert