Mysql – Logging MySQL events to file in addition to syslog on Debian

debiandebian-squeezeMySQLrsyslog

By default, Debian uses rsyslog to handle MySQL error logging. I like this behavior and do not want to change it. However, I would like rsyslog to write MySQL events to /var/log/mysqld.log in addition to the already functional /var/log/syslog. I believe this should be doable using rsyslog, so I do not want to use the MySQL --log-error command option.

After reading the my.cnf documentation section on --syslog, it seemed to me that the syslog facilities used would be called mysqld and mysqld_safe. Therefore, I tried adding the following to my rsyslog.conf:

mysqld.*                        -/var/log/mysqld.log
mysqld_safe.*                   -/var/log/mysqld_safe.log

However, nothing gets written to those files after restarting the rsyslog and mysql services. I touched the files and they are owned by root:adm like other similar files like /var/log/mail.log, which properly receives my postfix and dovecot events.

I am inexperienced with rsyslog, so I'm not sure what I'm doing wrong or how to further investigate this. It's made all the harder due to the wealth of information on logging syslog into MySQL, which is not what I am seeking to do. Any help would be appreciated.

Edit: On further investigation, I see that those are not valid facilities (which are predefined). So I therefore need to use an alternate method for filtering rather than by facility.

Best Answer

Adding the following lines to rsyslog.conf seems to produce the result I sought:

:syslogtag, isequal, "mysqld:" -/var/log/mysqld.log
& ~
:syslogtag, isequal, "mysqld_safe:" -/var/log/mysqld.log
& ~
:syslogtag, startswith, "/etc/mysql/debian-start" -/var/log/mysqld.log
& ~