Run MySQL commands through bash

I wanted to log some stats from MySQL.  The following outputs a few statistics (filtered with grep)

mysql -ppass -e 'SHOW STATUS;' | grep -E '(Threads|[cC]onnections)' | column -t >> $logfile;

and this one shows the current MySQL config variables which have been loaded (Useful if you want to see if a change to the config file has been loaded)

mysql -uroot -ppass -e 'show variables'

Leave a Reply

Your email address will not be published. Required fields are marked *