Fixing wordpress blunder


While messing around with the URL configuration values in wordpress, I managed to kill my theme and the administrative screens. This unfortunate series of events forced me to call technical support (Clay), who quickly forwarded me one of his blog posts for a fix. I followed Clay’s directions, but inadvertently updated all 72 entries in the wp_config table with the following SQL DML statements:

mysql> update wp_options set option_value 'http://moneyslow.com/html/prefetch.net/blog';

Since my BLOG immediately died after this update statement, I started to investigate the layout of the wordpress tables to see how to best recover from this snafu. A quick check of the matty mysql database revealed the following tables:

$ mysql -p

Enter password:

mysql> use matty

mysql> show tables;

+-------------------+
| Tables_in_matty |
+-------------------+
| wp_categories |
| wp_comments |
| wp_linkcategories |
| wp_links |
| wp_options |
| wp_post2cat |
| wp_postmeta |
| wp_posts |
| wp_users |
+-------------------+
9 rows in set (0.00 sec)

Since I didn’t have a backup* of the wp_config table, I couldn’t just use the SQL TRUNCATE, DROP, CREATE and INSERT statements to remove the table and re-create it. Since I wanted to get my BLOG restored quickly, I decided to DROP the wp-config table and backup the “mattyâ€? database with mysqlbackup:

$ mysql -p

Enter password:

mysql> drop table wp_config;

$ mysqldump -u matty -p matty > mattydb.dump

Once I had a good backup with the data I wanted to save, I proceeded to drop all of the remaining tables to allow wp-install.php to work (wp-install.php doesn’t seem to want to run if the wp_* tables are already defined). Once the wp-install.php script initilized the schema and loaded the initial configuration data, I copied (‘grep’ and “»” actually) the pertinent INSERT statements from the dump file to a file called import.sql. Next I fired up mysql and executed all of the INSERT statements I had filtered:

$ mysql -p

Enter password:

mysql> source import.sql

This imported all of the data I had input with the wordpress graphical editor, and my BLOG was restored to a happy state. :) I cannot emphasize enough how important backups are! :) I have since implemented daily backups of the database!

This article was posted by Matty on 2005-09-09 22:30:00 -0400 -0400