I'd like to monitor a MySQL 5.0.77 server and log every incoming connection for a day. I need to know who is connecting to the database.
I tried with the general logging but it's logging way too much and I can't keep it on long enough, log file is growing too fast.
Is there a way to do that ? Thanks
You should use general log, not as a text file, but as a MySQL table.
Why create the general_log as a table?
How do you configure it?
Starting in MySQL 5.1, the following option was introduced: log-output.
log-output
toFILE
(default) writes log entries to the text file.log-output
toTABLE
writes log entries tomysql.general_log
.log-output
toTABLE,FILE
writes log entries tomysql.general_log
and the text file.There is one major thing that must be changed.
Let's look at a standard mysql.general_log table:
It's a CSV file ? Yuck !!! Who has time for that? Not to worry, turn it into a MyISAM table
If you already started MySQL, do it like this instead:
Now, the general log table looks like this:
How do you rotate the general log when it's a MyISAM table?
Here is an example of how to blank out
mysql.general_log
:Here is an example of how to keep the last 3 days of entries:
CAVEAT
This feature is available in MySQL 5.1/5,5/5.6. You should upgrade from MySQL 5.0.77 to the latest
EPILOGUE
I could write a lot more here but have discussed this many times in the DBA StackExchange. here are some of my posts on this subject:
Feb 11, 2012
:MySQL general log
Jan 07, 2012
:How to enable MySQL general log?
Dec 27, 2011
:How to do MySQL User Accounting
Feb 24, 2011
:Audit logins on MySQL database
Here's an idea, but it might not work.
Create a FIFO pipe in
/var/log/mysql/named_pipe
In one end, get MySQL to use it as the general log file filename.On the other end, set up something like
You'll need to grep for whatever line it is exactly that you're after out of the log.
It might work.. it might not.
I needed to do the same thing. In MySQL 5.6 and MySQL 5.7, there is a way to capture the information needed and store it in a table. I'm not sure if this is possible with MySQL 5.0 or 5.5. Here is what I did:
Note: This will not capture information if a user connects with super or root like privileges.
In the mysqld section of the MySQL configuration file, I added:
# ***
Parameter below logs user connectionsInformation I need to capture is userid, host the connection request is coming from, the database the user is connecting to, information about the connection, and a timestamp.
I use this information to determine who is using an encrypted connection, what database(s) they are connecting to, and when the user connects.