mysql-tail

mysql-tail a script for temporarily enabling mysql's general_log and then tailing the output.

usage: mysql-tail [connect args]

$ mysql-tail -uroot -p

The script will prompt you for a password if required both on startup and shutdown, both when it connects to enabled the general query log and when it disables the log. I typically use this in development with mysql restricted to connections from localhost and without a password.

usage without a password and a default user from ~/.my.cnf:

$ mysql-tail

installation:
wget https://safetytrick.com/snippets/mysql-tail && chmod +x mysql-tail

script:

#!/bin/bash

export allargs="$@"

mysql_genlog_off () {  
  mysql $allargs -e "set global general_log = 0;"    
  exit $?
}

if [ "OFF" = $(mysqladmin variables | grep -w general_log | awk '{print $(NF-1)}') ]  
then  
  trap "mysql_genlog_off" SIGINT
  mysql $@ -e "set global general_log = 1;"
fi 

LOGFILE=$(mysqladmin variables | grep general_log_file | awk '{print $(NF-1)}')

if [ ! -f $LOGFILE ]  
  then
  echo "general_log_file does not exist: $LOGFILE"
  exit 1
fi

echo "reading from: $LOGFILE"  
tail -F $LOGFILE