Skip to content

Instantly share code, notes, and snippets.

@steffen-wirth
Forked from colinmollenhour/mysql_monitor.sh
Last active August 29, 2015 14:08
Show Gist options
  • Save steffen-wirth/bd9064e1b6cae4d06595 to your computer and use it in GitHub Desktop.
Save steffen-wirth/bd9064e1b6cae4d06595 to your computer and use it in GitHub Desktop.
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment