Repairing the MySQL WordPress Database

You can recover a running MySQL database with the mysqlcheck command.

After a power cut, I found these errors in /var/log/daemon.log. This was on Debian Squeeze running WordPress 3.3.1 and MySQL 5.1.61.

Mar 22 11:22:16 debian /etc/mysql/debian-start[2153]: Triggering myisam-recover for all MyISAM tables
Mar 22 11:22:17 debian mysqld: 120322 11:22:17 [ERROR] /usr/sbin/mysqld: Table './wordpress/wp_commentmeta' is marked as crashed and should be repaired

Mar 22 11:22:17 debian mysqld: 120322 11:22:17 [Warning] Checking table: './wordpress/wp_commentmeta'
Mar 22 11:22:17 debian mysqld: 120322 11:22:17 [ERROR] /usr/sbin/mysqld: Table './wordpress/wp_comments' is marked as crashed and should be repaired
Mar 22 11:22:17 debian mysqld: 120322 11:22:17 [Warning] Checking table: './wordpress/wp_comments'
Mar 22 11:22:17 debian mysqld: 120322 11:22:17 [ERROR] /usr/sbin/mysqld: Table './wordpress/wp_options' is marked as crashed and should be repaired
Mar 22 11:22:17 debian mysqld: 120322 11:22:17 [Warning] Checking table: './wordpress/wp_options'
Mar 22 11:22:17 debian mysqld: 120322 11:22:17 [ERROR] /usr/sbin/mysqld: Table './wordpress/wp_postmeta' is marked as crashed and should be repaired
Mar 22 11:22:17 debian mysqld: 120322 11:22:17 [Warning] Checking table: './wordpress/wp_postmeta'
Mar 22 11:22:17 debian mysqld: 120322 11:22:17 [ERROR] /usr/sbin/mysqld: Table './wordpress/wp_posts' is marked as crashed and should be repaired
Mar 22 11:22:17 debian mysqld: 120322 11:22:17 [Warning] Checking table: './wordpress/wp_posts'
Mar 22 11:22:17 debian mysqld: 120322 11:22:17 [ERROR] /usr/sbin/mysqld: Table './wordpress/wp_term_relationships' is marked as crashed and should be repaired
Mar 22 11:22:17 debian mysqld: 120322 11:22:17 [Warning] Checking table: './wordpress/wp_term_relationships'

The database was recovered as follows.

root@debian:/var/log# mysqlcheck –user=<username> –password=<password> -r wordpress
wordpress.wp_commentmeta OK
wordpress.wp_comments OK
wordpress.wp_links OK
wordpress.wp_options OK
wordpress.wp_postmeta OK
wordpress.wp_posts OK
wordpress.wp_term_relationships OK
wordpress.wp_term_taxonomy OK
wordpress.wp_terms OK
wordpress.wp_usermeta OK
wordpress.wp_users OK

where <user> is the name of the database user you created when installing WordPress and <password> is the associated password. “wordpress” is the name of the database instance.

One thought on “Repairing the MySQL WordPress Database

Leave a Reply

Your email address will not be published. Required fields are marked *