Replacing characters in MySQL table data

This may be useful when for example the character encoding has been messed up and you need to correct existing data.

This example will correct swedish accented characters in a uft8 – latin1 mixup.

UPDATE my_table
SET my_field = REPLACE(my_field,'Ã¥','å');
 
UPDATE my_table
SET my_field = REPLACE(my_field,'ä','ä');
 
UPDATE my_table
SET my_field = REPLACE(my_field,'ö','ö');
 
 
UPDATE my_table
SET my_field = REPLACE(my_field,'Ã…','Å');
 
UPDATE my_table
SET my_field = REPLACE(my_field,'Ä','Ä');
 
UPDATE my_table
SET my_field = REPLACE(my_field,'Ö','Ö');

(Yes, you can concatenate them if you like but they become very hard to read.)

Comments

One Comment so far. Leave a comment below.
  1. tinga brasil,

    Very very very useful!!

Add Your Comments

Required
Required
Tips

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <ol> <ul> <li> <strong>

Your email is never published nor shared.

Ready?