Sunday Morning MySQL issues..

You’d think I get to sleep in most Sunday mornings. Well, I do. Most Sundays, that is. However, this Sunday is a different story. Our hosting server (cpanel) has had issues for quite some time and likes to reboot itself at random times.. usually it comes up fine. This case it did not.

The server runs ‘fsck’ to scan the drives for any errors when it reboots, since it doesn’t unmount them on the crash. I know, it sucks. This time, my data in the /var/db/mysql/mysql folder had some issues. The mysql permissions tables are what resides in there. So MySQL refused to start. What a joke.

So I moved the mysql folder to mysql_old, re-ran the mysql_install_db script to regenerate the permissions table. Then set my mysql ‘root’ password. Lucky for me, cpanel backs up the MySQL user privileges in the users backup directory every night (or is it morning?).

So some quick bash scripting later:

for blah in $( ls /backup/cpbackup/daily/*/mysql.sql ); do
echo "Restoring.. $blah"
mysql --password=secretmysqlpassword mysql < $blah
done;

And I have all my user permissions back in the database. It probably would have been easier had I had a recent backup of the mysql database. But this way, I have the passwords in tact.

Nothing like writing some bash scripting, and fixing server issues at 6:30am on a nice sunday morning.

Back to bed..

Leave a Reply

You must be logged in to post a comment.