Fixing Errors in MySQL: How to Find & Replace

January 27, 2009

in Web Geekery

I recently exported a MySQL database for a WordPress blog from GoDaddy and uploaded it to MediaTemple.  It was a pretty straight-forward process, but I noticed a few days after the import that many weird symbols start cropping up such as

”
“
•

If this happens to you, fear not!  You can simply access your MyPHPAdmin panel, click on the SQL tab, and run a very simple find and replace command.  Here are the commands I used for my WordPress site:

update wp_posts set post_content = replace(post_content,’•’,'–’)

update wp_posts set post_content = replace(post_content,’“’,'‒’)

update wp_posts set post_content = replace(post_content,’”’,'”’)

The command can also be expressed more generically as the following formula:

update [table_name] set [field_name] = replace([field_name],’[string_to_find]‘,’[string_to_replace]‘);
If you’re not familiar with MySQL, I’d ask an expert to help you out before you attempt anything like this.  And always remember: BACKUP!
Computers allow you to have infinite do-overs, so they’re great for teaching yourself a new set of skills. But, if you don’t backup, you’re screwed.

Share Share    Print Print    Email Email

Comments on this entry are closed.

Previous post:

Next post: