steffen-wirth
10/22/2014 - 7:55 PM

mysql_monitor.sh

#!/bin/bash
#
# Monitor MySQL queries
# @author Colin Mollenhour

file=$(mysql -Be 'SHOW VARIABLES LIKE "general_log_file";' | tail -n 1 | awk '{print $2;}')
echo "SET GLOBAL general_log = 'ON';" | mysql
if [ -w "$file" ]; then
    >$file
    tail -f $file
else
    sudo bash -c ">$file"
    sudo tail -f $file
fi
echo "SET GLOBAL general_log = 'OFF';" | mysql