MySQL: Fix Microsoft Word characters. Shows weird characters on the web page.

As a consultant, I do a lot of content migrations for clients. One issue I run into quite often is the encoding of databases, tables, columns differs between source and destination. Most clients do not want me to go and change the way their encoding is to fix issues since they are too afraid about messing with production data. Of course amongst other issues, it creates weird characters for data which is copied/pasted from Microsoft Word. You see weird characters like: ’ … – “ †‘

So if you just want to replace these with appropriate symbols, you may do it with a simple sql query. Note that below queries are without where clause. You may what to test it with one of your rows before making changes to the whole table. Of course, you should always backup your data before you try this out. If you have a dev system, that is even better. I put all my sql queries into a file ex: fix.sql and sourced it with mysql client.

vi fix.sql

update table_name set fieldname = replace(fieldname, '’', '\'');
update table_name set fieldname = replace(fieldname, '…','...');
update table_name set fieldname = replace(fieldname, '–','-');
update table_name set fieldname = replace(fieldname, '“','"');
update table_name set fieldname = replace(fieldname, '”','"');
update table_name set fieldname = replace(fieldname, '‘','\'');
update table_name set fieldname = replace(fieldname, '•','-');
update table_name set fieldname = replace(fieldname, '‡','c');

Save/exit.

# mysql
mysql> source fix.sql;

I am not sure if I am missing any other chars. If you know of any other chars, please comment with them and I will add on to the script here.

————————————-
DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. Use at your own risk.

13 thoughts on “MySQL: Fix Microsoft Word characters. Shows weird characters on the web page.

  1. Chris Henry

    Wow…this looks like it will do exactly what I’m looking for. I run a job posting site where users will often paste directly from Word, and wind up with lots of these characters. Do you have a php equivalent?

  2. Pam

    It ‘called one of the best photo editing software.
    Rich in effects and customization with amazing lighting effects that allow you to make your photos beautiful masterpieces.
    Thousands of people satisfied, now for you is under discount.
    Take advantage of it, use IMAGIC PHOTO! info and buy–> http://9nl.co/ImagePhoto

  3. Carl

    The Complete FroKnowsPhoto 6-Hour Guide to DSLR Video Now you can learn the fast track system used by a world class photographer and videographer to shoot, direct, and produce any type of video with a DSLR, regardless of your current skill level. http://9nl.co/HotNewProduct

  4. Saundra

    It ‘called one of the best photo editing software.Rich in effects and customization with amazing lighting effects that allow you to make your photos beautiful masterpieces.Thousands of people satisfied, now for you is under discount.Take advantage of it, use IMAGIC PHOTO! info and buy–> http://9nl.co/ImagePhotoSoftware

  5. Eddie

    It ‘called one of the best photo editing software.Rich in effects and customization with amazing lighting effects that allow you to make your photos beautiful masterpieces.Thousands of people satisfied, now for you is under discount.Take advantage of it, use IMAGIC PHOTO! info and buy–> http://9nl.co/ImagePhotoSoftware

  6. yeezy boost 350 v2

    I wish to show some thanks to this writer just for bailing me out of such a predicament. Right after researching throughout the online world and finding basics which are not powerful, I was thinking my entire life was gone. Existing devoid of the strategies to the problems you’ve fixed by means of your website is a critical case, as well as the kind which might have adversely affected my career if I hadn’t discovered your web page. That understanding and kindness in playing with every item was crucial. I don’t know what I would’ve done if I had not come upon such a subject like this. It’s possible to now look forward to my future. Thank you so much for your expert and effective help. I will not be reluctant to suggest your web blog to any person who should receive guidance on this issue.

  7. stephen curry 5

    I and my guys have been studying the great guidelines on your website and so unexpectedly came up with a terrible feeling I never expressed respect to the site owner for those strategies. All the ladies are actually for this reason very interested to read through them and have unquestionably been enjoying them. I appreciate you for getting quite accommodating and then for deciding on these kinds of essential ideas most people are really wanting to be informed on. My personal sincere apologies for not expressing gratitude to earlier.

Leave a Reply

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