Created
July 3, 2012 23:39
-
-
Save claytonaalves/3044166 to your computer and use it in GitHub Desktop.
Real-time MySQL query log analyzer with source highlight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Author : Clayton A. Alves | |
# License : I don't care... | |
# Date : 2012-06-06 | |
# | |
# Real-time MySQL query log analyzer with source highlight | |
# (displays executed queries colorized on screen) | |
# | |
# Requires: | |
# - Gnu Source-highlight (http://www.gnu.org/software/src-highlite/source-highlight.html) | |
# | |
clear | |
cleanup() | |
{ | |
mysql -e "SET GLOBAL general_log='OFF'" | |
echo -e '\n---> MySQL log disabled!' | |
exit 0 | |
} | |
trap cleanup SIGINT | |
> /var/run/mysqld/mysqld.log | |
chown mysql:mysql /var/run/mysqld/mysqld.log | |
mysql mysql <<EOF | |
SET GLOBAL log_output='FILE'; | |
SET GLOBAL general_log='ON'; | |
EOF | |
echo '--- Executed queries ---------------------' | |
tail -n +4 -f /var/run/mysqld/mysqld.log | sed -u -e 's/^.\+Query\t//' -e '/^.\+Connect\t/d' -e '/^.\+Quit\t/d' | source-highlight -fesc -ssql -oSTDOUT | |
echo '--------------------------------------------' | |
echo | |
mysql mysql <<EOF | |
SET GLOBAL general_log='OFF'; | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment