Skip to content

Instantly share code, notes, and snippets.

@gorbiz
Last active August 29, 2015 14:13
Show Gist options
  • Save gorbiz/c897800a27fa4f03578c to your computer and use it in GitHub Desktop.
Save gorbiz/c897800a27fa4f03578c to your computer and use it in GitHub Desktop.
Turn MySQL logging on & off
#!/bin/sh
if [ "$1" = "on" ]; then
mysql -e 'SET GLOBAL log_output = "FILE"; SET GLOBAL general_log_file = "/tmp/mysql.log"; SET GLOBAL general_log = "ON";'
echo "mysql log ON: /tmp/mysql.log"
elif [ "$1" = "off" ]; then
mysql -e 'SET GLOBAL general_log = "OFF";'
echo "mysql log OFF"
elif [ "$1" = "tail" ]; then
mysql -e 'SET GLOBAL log_output = "FILE"; SET GLOBAL general_log_file = "/tmp/mysql.log"; SET GLOBAL general_log = "ON";'
echo "tailing mysql log /tmp/mysql.log..."
tail -f /tmp/mysql.log
else
echo "Usage: sqlog on|off|tail"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment