Is there a way to fix an encoding issue directly in my Mysql?

I’m having an issue with my WordPress install. Somehow all the content was inserted in the database with a wrong charset, but in the frontend is working smoothly.

As you can see here:
http://prntscr.com/8vifc3

Read More

I’m changing my host, but when I imported my site won’r render the encoding properly because of the way that the content was inserted.

There’s a way so I can fix the encoding directly in my previous mysql before I export it?

Thanks

Related posts

3 comments

  1. You can fix the issue by converting your strings to binary and then do charset conversion. The example below converts UTF8 data to CP1251:

    UPDATE table SET column=CONVERT(CONVERT(CONVERT(column USING binary) USING utf8) USING cp1251) WHERE id=123;
    
  2. you can use set_charset` function

    in mysqli

    $mysqli->set_charset("utf8")
    

    or you can change the charset from phpmyadmin to utf8_*

  3. That’s Mojibake

    • The bytes you have in the client are correctly encoded in utf8 (good).
    • You connected with SET NAMES latin1 (or set_charset('latin1') or …), probably by default. (It should have been utf8.)
    • The column in the tables may or may not have been CHARACTER SET utf8, but it should have been that.

    If you need to fix the data it takes a “2-step ALTER”, something like

    ALTER TABLE Tbl MODIFY COLUMN col VARBINARY(...) ...;
    ALTER TABLE Tbl MODIFY COLUMN col VARCHAR(...) ... CHARACTER SET utf8 ...;
    

Comments are closed.