Thursday, May 31, 2012

Fixing MySQL tables in Fedora 17

I had some largish databases in my Fedora 16 installation so when I moved to Fedora 17 I copied back the files from the backup to /var/lib/mysql and tried to start MySQL as usual:
# systemctl start mysqld.service
Unfortunately, it got stuck attempting to start it, with syslog being filled with messages like this:
May 31 12:33:40 novo systemd[1]: mysqld.service holdoff time over, scheduling restart.
May 31 12:33:40 novo systemd[1]: Job pending for unit, delaying automatic restart.
so something was obviously wrong. First, I blamed wrong file permissions or SELinux. Unfortunately, the pair of commands:
# chmod -R mysql.mysql /var/lib/mysql
# restorecon -R /var/lib/mysql
did not fix it. Digging with Google it turns out I need to the mysql_upgrade command but that needs to connect to a running instance. uhm...
So the solution to this chicken-and-egg problem was to manually start mysql with the --skip-grant-tables options like this:
# su - mysql -c "/usr/libexec/mysqld --skip-grant-tables"
then running in another shell:
# mysql_upgrade -u root -p
# systemctl restart mysqld.service