Monday, June 19, 2006

Run a command on multiple MySQL hosts

cat /lists/dbs | while read i ; do echo $i; /path/to/mysql -h $i -e "SHOW variables like 'old%'"; done


This programming one liner allows you to run a command on multiple MySQL hosts. To use this command, simply create a file dbs with all the MySQL hosts (one per line). The sample command prints the value of whether the database is using old passwords.

2 comments:

Anonymous said...

Here's a different way:

xargs -n 1 mysql -e "..." -h < /lists/dbs

Frank said...

Thanks Toby for the alternative way.
Frank