Jürgen Steinblock
Jürgen Steinblock

Reputation: 31743

MySQL how to log thread connections (I need user and ip)

From time to time I need to parse my mysql binlog to find out which query changed a specific value in my database.

A query entry looks like this:

# at 335156
#101208  5:55:57 server id 1  end_log_pos 335265    
         Query  thread_id=1772  exec_time=0 error_code=0
SET TIMESTAMP=1291784157/*!*/;
UPDATE table SET value = 0 WHERE id = 185555

Now If I figured out the specific query I have the thread_id but where do I find the corrosponding user / ip from this entry?

Upvotes: 1

Views: 3195

Answers (1)

Andreas Wederbrand
Andreas Wederbrand

Reputation: 40021

First you have to enable the genereral query log http://dev.mysql.com/doc/refman/5.5/en/query-log.html

Then you can find all connects and what queries they ran there. I word of warning, this log gets big so use with care.

This is an example of my connect as root to my local server just now.

101208 10:55:18      5667 Connect  root@localhost on 
                     5667 Query select @@version_comment limit 1
101208 10:55:26      5667 Query show databases

Upvotes: 1

Related Questions