Wednesday, July 14, 2010

Basic MySQL 'top' command

Ever wanted to keep an eye on the running processes in a MySQL database? How about something that works a little like the top command, but without any of the bells and whistles?

Well, here you go:

> while [[ 1 ]];
do
clear;
mysql -u <username> -p<password> -h <host> -e "show full processlist";
sleep 1;
done


Remember to replace the <username> <password> and <host> variables with the values for your database. Also, if you don't like the bounding box on the mysql output, you can have a cleaner output by using redirection instead of the -e flag:

mysql -u <username> -p<password> -h <host> <<< "show full processlist";

2 comments:

  1. You can try using `watch` to similar effect:

    watch "mysql -u [username] -p[password] -h [host] -e 'show full processlist'"

    ReplyDelete
  2. Thanks, Pat. 'watch' gives a much cleaner display. Using 'clear' produces an obvious flicker...

    ReplyDelete