Here is a small BASH script I wrote for root users to easily enable/disable MySQL general query logging. It will show status, create a log file, and replace the file with a symbolic link to /dev/null when disabling logging. A good place for the script is “/root/bin/”.
You will need to add the following to “/etc/my.cnf” and then either restart MySQL or give it a SIGHUP:
log=/var/log/mysql-generalquery.log
Download at: http://wp.css-solutions.net/dl/mysqllog
#!/bin/bash
# mysqllog - Enable/Disable MySQL logging - By Joe C
if [ -z "$1" ] ;then # No option given
if [ -f /var/log/mysql-generalquery.log ] ;then echo "MySQL general query logging is enabled to /var/log/mysql-generalquery.log"
else
if [ -h /var/log/mysql-generalquery.log ] ;then echo "MySQL general query logging is disabled"; fi
fi
echo "USAGE: mysqllog <on|off>"
else # Option present
if [[ "$1" = [Oo][Nn] ]] ;then
if [ -f /var/log/mysql-generalquery.log ] ;then echo "MySQL general query logging is already enabled to /var/log/mysql-generalquery.log"
else
rm -f /var/log/mysql-generalquery.log
touch /var/log/mysql-generalquery.log
chown 0:mysql /var/log/mysql-generalquery.log
chmod 664 /var/log/mysql-generalquery.log
kill -SIGHUP `cat /var/lib/mysql/$(hostname).pid` > /dev/null 2>&1
echo "MySQL general query logging is now enabled to /var/log/mysql-generalquery.log"
fi
else
if [[ "$1" = [Oo][Ff][Ff] ]] ;then
if [ -h /var/log/mysql-generalquery.log ] ;then echo "MySQL general query logging is already disabled"
else
rm -f /var/log/mysql-generalquery.log
ln -s /dev/null /var/log/mysql-generalquery.log
chown -h 0:mysql /var/log/mysql-generalquery.log
echo "MySQL general query logging is now disabled"
fi
fi
fi
fi