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
Best Answer
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