How to Convert Your Old WordPress Database to UTF8

When I upgraded my WordPress installation recently, I ran into a chracter encoding problem. Long story short, it turns out that older WordPress installations like mine tend to have been created in latin1, but the data is actually being saved in UTF8. If you update your wp-config file to a newer version, it adds a DB_CHARSET option, which will cause your site to puke, because the database character set doesn’t match the data that’s actually stored in it.

Thankfully, the fix is relatively simple, if a bit of a hassle:

  1. From your command line, use the mysqldump command to export your database in latin1 format. Since MySQL sees your database is already in latin1 format, it won’t re-encode it (which would break the UTF8 data in the database). The command should look something like this:
    mysqldump -u username -p --add-drop-table --default-character-set=latin1 databasename > databasename.sql

    Note: You must do this from the command line, because PHPMyAdmin doesn’t allow you to specify the characterset of the export file, so you will end up with re-encoded data, that will get scrambled and kill your database.

  2. Copy that dump file somewhere safe for a backup, in case something goes wrong.
  3. Using a text editor, open the MySQL dump file and replace all instances of latin1 with utf8. There should be one reference in each CREATE TABLE line.
  4. Import the database over the top of your existing one. Since you did a complete dump, with the add-drop-table option, this will drop all your existing tables, and recreate them. And since you changed the character sets, this will effectively update your database to UTF8. The command will look something like this:
    mysql -u username -p databasename < databasename.sql

Now, if you’re anything like me, those instructions are terrifying. But trust me that there is relatively little risk. The very first thing you’re going to do is make a backup. If anything goes wrong, the worst case scenario is that you restore your backup, and you’re back to square one. I can’t tell you that it’s totally safe, but I can assure you that I did this to two of my databases, and it went off without a hitch.

WordPress Automatic Theme Upgrade Deletes Custom Files

When I made Dojo, one of the main features of the theme is the ability to add a custom.css file in the same directory, and the theme will load it – that way you can use the theme as a starting point, and just change the colors and stuff to match what you want. That’s how Sean’s blog works. It’s a stock installation of Dojo with a single custom.css file.

A few days ago, I released an upgrade to the theme to add support for some new features in WordPress 2.7, so I logged into Sean’s blog to upgrade the theme. Newer versions of wordpress added the ability to automatically notify users when a new version of a theme is available, and let them click on a link to automatically upgrade. Since I wasn’t sure how it would work, I backed up Sean’s files first, and then used the Upgrade Automatically feature.

It worked perfectly, except it deleted all his custom files! His custom.css file and some other images in the theme directory were just gone. No notification, nothing. Thankfully, I had the backup, so I could restore those files quickly, but I hate to think that someone out there is going to upgrade their installation of my theme this way, and lose all their work.

So please, if you use the Upgrade Automatically feature, make sure you have a backup of your files first, otherwise your custom files will be deleted!

Geek News

<GEEK NEWS>

Oh man. I’ve been through the best and worst ends of computers in the last week. I’ve formatted my computer four times, and Annie’s twice, and I still have to do it one more time because I somehow fried her hard drive.

The bad news was that all the upgrades didn’t always go smoothly, and I had to swap hardware around and check support sites and call Qwest again and again and generally had a miserable time just getting things to work.

The good news is that once I get Annie’s computer working again, we’ll both be up and running with Windows XP (or Microsoft FisherPrice as Steve referred to it) on much faster computers.

Fry’s had a fantastic sale that I caught yesterday, enabling me to upgrade my computer to an AMD Duron 950Mhz with 512MB RAM for $150. That means that Annie got my old components, giving her an Athlon 700 with 256MB RAM.

My system is fully upgraded and looking sharp. I’ll get a new screenshot posted soon.

</GEEK CODE>

And in other news, pretty much nothing is going on in my life outside of making computers work. We did have a fun New Year’s with KT and my brother Sean, though!

Macintosh OS X Release

So I’m at The Computer Store.

It’s 8:40 AM.

Saturday.

I’m behind the service counter eating Snak Pak Cheezy Bitz Peanut Butter Crackers.

Wearing an “X… The Future Is Here” T-shirt.

There are like 50 people in this small store milling around for the OS TEN RELEASE.

Floor manager has marked a printer-paper box as a ballot receptacle for the “Win A Copy Of Os X” drawing. He used not just a permanent, but an ultra-permanent marker. I can feel my face, my eyes and lips, burning from the toluene vapors. Neurons sloughing off my medulla and puddling around my brainstem.

So I’m coming live to you from the OS Ten release and I must say I feel sorry for all these people who got up at got knows what hour to queue up in front of the store at 7:45, eighteen deep, to come look at Ten. I mean, we should at least have some carnival clowns or a ferris wheel in here to liven things up, I mean at least a monkey grinder, come on man. OOH LOOK THE “DOCK” and “AQUA” ! THE ICONS RESEMBLE POLISHED GEMS!

My boss just told me he thought it was a bust. We weren’t selling very many copies. He wouldn’t buy OS Ten. It sucks, now. It’ll be great in six months. Shrug. He walked away. Then a gum wrapper came flying through the air, caromed off my thigh and into the trash can. “Ha! Bank shot off the knee!”

My coworker fears the “weenies” who are going to be bringing their sick computers in to us, having hosed the BSD-based installations of MacOS through their insistence on tinkering with THAT WHICH THEY UNDERSTAND NOT. The Terminal (a command-line interface to OS ten’s BSD foundation) provides infinite ways for them to mess up their systems.

With MacOS 9 or earlier, you could fix almost any problem with one of three methods short of a clean install:

  1. reinstall part of the software
  2. uninstall part of the software
  3. run a disk-checking utility

With 10, excuse me, X, it’s going to be like, “Oh you’ve got malformed XML in your mtab which is causing your Zip disk to emit that horrible clicking noise. You need to renice your nohups to 0xfdeadbeef” and blood will start gushing from the customer’s ears. “What?? What are you talking about, you horrible technical person? I can’t understand you!!” Whereas before, we could just say, “reinstall the Zip software.” Well, I hope I’m wrong and you can still deal with things at that high level of installers and control panels, because otherwise the answer to every question is going to be, “bring it in. We’ll fix it.”

Whew… the very thought of building a consumer OS on BSD… it’s like some horror movie where a band of occultists form a corporation and start selling people demon powered cars.. only the customers don’t understand the black creeping power that lurks within their engine compartment and due to their throwing the salt over the wrong shoulder it bursts out one day in tentacular horror and devours them.

So yeah, I’d wait six months.

FUUUUUCK

My apologies to any family members or readers of a more linguistically-sensitive nature, but it was needed. For you see, I have acquired somewhat of a cursed touch with computers recently.

PART THE FIRST: In which I purchase the upgrade to The Sims (which works fine on both Annie’s Win98 box and my Win2K box), only to discover that the upgrade doesn’t work in Windows 2000.

PART THE SECOND: In which I attempt to upgrade Annie’s video card drivers and BIOS, and end up frying the card in the process. Diagnosis still uncertain. Tech support’s only suggestion doesn’t look promising. How much am I willing to put into a new video card for an old machine?

PART THE THIRD: In which I manage to delete an entire hard drive from my machine while attempting to create a dual-boot with Windows 98. Final Diagnosis: Dual-booting achieved successfully, at the cost of the entire contents of a 14GB hard drive, containing a year’s worth of MP3 harvesting (8GB) and ALL of my graphics files (a HUGE deal to a graphic designer). Some of these graphics can be restored from a backup. Some, such as the Myst3 Photoshop files from the job I just did, are unrecoverable.

Sometimes it’s better to just leave things as they are, rather than obsessively attempt to update and upgrade them, but hindsight is 20/20.