I imported 900 odd articles from a website we’re migrating from another system into WordPress. The information was in CSV format, so I built a quick and dirty PHP script to import the data directly into the database. I thought this might cause issues, but thankfully, it didn’t!
The problem came however, when I switched permalinks to %postname% as per the proposed structure for the new site. The pages list in the admin system showed no entries, and the front end just 404’d.
I started by altering line 1112 of wp-includes/wp-db.php to die if a mysql_error() was raised.
This pointed me to the query where WordPress updates it’s own rewrite_rules information in the wp_options table.
Reading around a bit, the exact error “the MySQL server has gone away” relates to MySQL setup, and specifically, the setting for wait_timeout. Altering this did nothing in my eyes, even after raising it to 600 (10 minutes). Poking around a bit more, I wondered if it was the pure size of this query. As I was using wampserver locally, I didn’t mind messing with the MySQL setup (my.ini), and thus, I also increased a couple of other variables. The one that did the trick was max_allowed_packet, which I increased to 64M (I believe the default is 1M).
The site now functions without a problem. When the site is deployed, this value will no doubt be tweaked, or may already be higher by default.
A useful one to remember in the future!
Comment or tweet @douglasradburn