I want to use syslog for logging MySQL(5.1.41) on Ubuntu(10.04 LTS). I found information that output error log to syslog.


But I want to use syslog for logging general logs and slow query logs. Please advise me how to write config file?

I could not find how to do that in the reference manual.


  • I am sure many have asked this question. Therefore, you a get +1 for revealing this quesiton publicly. Commented Aug 5, 2011 at 22:07
  • CAUTION: 5.7.5 may be changing the spelling to log_syslog.
    – Rick James
    Commented Nov 20, 2017 at 16:52

3 Answers 3


This is MUCH more simply done this way:

cd to mysql folders:

mkfifo mysql-general.log

in my.cnf tell it:

general-log-file = /path/to/mysql/dir/mysql-general.log

Then, configure your syslog/syslog-ng to read the FIFO pipe and do with it as it will..

In my case, I pipe it across net to a centralized server with only the error logs and slow query logs however.

In situations where you want to also keep local copy, just set it to output to table and file as described above.

  • That method sound intriguing. One just must prepare their network for torrents of traffic because everything and its grandmother lands in the general log. This would definite suit enterprise installations that stringently check every command and every userid that logs in. This is a +1 !!! Commented Aug 27, 2011 at 20:51
  • 3
    fifo's also have the unfortunate tendency to freeze any listening programs if they are not being written too. So, if MySQL stops writing to this fifo, then syslog may also stop. Commented Oct 9, 2013 at 22:16

That mechanism is entirely different from the OS syslog.

Setting log-output can be set either to TABLE, FILE (default), or NONE

if you use this


This will cause the logging for the general log and/or slow log to go to a CSV file. You can convert that CSV to MyISAM as follows:

SET @old_log_state = @@global.general_log;
SET GLOBAL general_log = 'OFF';
ALTER TABLE mysql.general_log ENGINE = MyISAM;
ALTER TABLE mysql.general_log ADD INDEX (event_time);
SET GLOBAL general_log = @old_log_state;

You can then let this file grow tremendously and you will have to purge the table every so often. Here is how to purge the general_log table and keep the last 3 days:

SET @old_log_state = @@global.general_log;
SET GLOBAL general_log = 'OFF';
CREATE TABLE mysql.general_log_new LIKE mysql.general_log;
INSERT INTO mysql.general_log_new
SELECT * FROM mysql.general_log WHERE event_time > NOW() - INTERVAL 3 DAY;
DROP TABLE mysql.general_log;
ALTER TABLE mysql.general_log_new RENAME mysql.general_log;
SET GLOBAL general_log = @old_log_state;

What about the syslog (var/log/messages) ? You must script that yourself. First, you either need this:


if you want to collect the general log in both formats or


for just the file format.

Now make a script to collect changes to /var/log/general.log. The script should look a lot like this:

NEWCOUNT=`wc -l < /var/log/mysql-general.log`
if [ -f /tmp/general-log-lines.txt ]
    OLDCOUNT=`cat /tmp/general-log-lines.txt`
    if [ ${OLDCOUNT} -lt ${NEWCOUNT} ]
        DIFF=`echo ${NEWCOUNT}-${OLDCOUNT}|bc`
        tail -${DIFF} < /var/log/mysql-general.log >> /var/log/messages
        echo ${NEWCOUNT} > /tmp/general-log-lines.txt

Run this script every minute. I recommend truncating the general log every midnight like this

echo -n > /var/log/mysql-general.log

Give it a Try !!!


In /etc/my.cnf, set it.

general-log-file = /path/to/mysql/dir/mysql-general.log

Edit /etc/rsyslog.conf (RHEL/CentOS) file, and enable module imfile to read /path/to/mysql/dir/mysql-general.log and then, send it to remote syslog server, respecting an interval configured in the PollingInterval parameter.

This section should look like this below:

module(load="imfile" PollingInterval="1")


Uncoment the line with WorkDirectory

$WorkDirectory /var/lib/rsyslog # where to place spool files

And configure it to send all logs remotely

*.* @@remote-ip:514 ## For TCP Connection


 *.* @remote-ip:514 ## For UDP Connection
  • 2
    You may want to avoid editing /etc/rsyslog.conf itself, and use a file created in /etc/rsyslog.d to control your custom tunings. The drop-in files preserve the checks of distro configs with respect to upgrades, and are easy to package and synch to other hosts. Compare /etc/php.d, /etc/sysctl.d and /etc/security/limits.d . Commented Nov 10, 2016 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.