Sunday, March 27, 2011

Mysql - flush-hosts

My organization's mysql server always needed to execute mysqladmin -flush-hosts command (1 week interval). I don't want to do that everytime our web server could't contact its database server. So what am I to do? Well, I tried using cron but the mysql server need to be authenticate to run mysqladmin command. At last, I found one solution. EXPECT! How?

Make sure you install expect in your mysql server (Centos Linux). Just issue command

yum install expect

Then, make a script file like this:

#!/usr/bin/expect
set timeout 20
spawn /usr/bin/mysqladmin -p flush-hosts

expect "Enter password: "
send "yourmysqlrootpasswd\r\n"

save this script and add this script to run in cronjob.

That's it. Done. You might want to chmod this script to 700 first.

No comments:

Post a Comment