0

Somehow, data in MySQL database has been converted from Unicode to ANSI and caused a lot of the symbols that are in the system to display incorrectly.

Symbols now display like:

  • –
  • •
  • ₸
  • Ω
  • etc.

I would like to convert it back to Unicode...
I have tried:

  • Re-importing the database as UTF8 character set
  • Using Notepad++ to "convert to UTF8..."
  • Added default charset UTF8 to Apache config...
  • A PHP script that takes all the DBs and tables, copies them, converts the data, then re-creates the original databases.

These methods did not work out... they seem to just leave my data the way it is, but any future attempts to use symbols works fine.
I want to convert these existing misinterpretations back to their original forms!


Hex output of an example text from the DB.

SELECT hex(name) FROM table_name where id = 17;

which is equivalent to: SELECT hex('☼STICKY☼');

OUTPUT: C3A2CB9CC2BC535449434B59C3A2CB9CC2BC

8
  • Do you see the mangled characters using phpMyAdmin? It is possible that your data in mysql are correct and only you can't see them correctly.
    – Tomas M
    Feb 18, 2015 at 20:51
  • The data is showing the "mangled characters" from within mysql as well as from the application (browser). Using the application to place symbols into the database works fine NOW. Existing "mangled characters" stay mangled. I have been using the database and application with symbols just fine until early this week. Feb 18, 2015 at 21:50
  • Does using phpMyAdmin tend to cause this type of encoding error??? I am trying to understand why this has happened. I feel like it happened from some other admin doing export/import/backup/restore using phpMyAdmin... but its basically just a shot in the dark. I do not use phpMyAdmin to interact with my db Feb 18, 2015 at 21:52
  • I had similar experience where everything was displayed properly on webpage but phpMyAdmin showed it as like in your example. It turned out to be a problem of default connection between PHP and MySQL, not related to phpMyAdmin at all.
    – Tomas M
    Feb 19, 2015 at 8:13
  • I had similar experience when I exported data and then re-imported it. Using the --default-character-set was the thing i forgot in the mysqldump command:mysqldump --host=<host> --user=<user> --single-transaction --default-character-set=utf8 <database> > <file>
    – less
    Feb 19, 2015 at 12:58

1 Answer 1

1

The output you showed looked somewhat like "double encoding" and discussed in http://mysql.rjweb.org/doc.php/charcoll . Please dump a little of the text in hex for confirmation.

To clarify, you are probably looking at utf8 (not unicode) versus latin1 (not ANSI).

@Tomas M - In PHP, mysqli_set_charset('utf8') is the proper call, not SET NAMES utf8.

However, if the data is mangled in the table(s), that call will not help.

(Edit -- added after HEX by OP)

mysql> SELECT hex(convert(convert(unhex('C3A2CB9CC2BC') using utf8) using latin1));
+----------------------------------------------------------------------+
| hex(convert(convert(unhex('C3A2CB9CC2BC') using utf8) using latin1)) |
+----------------------------------------------------------------------+
| E298BC                                                               |
+----------------------------------------------------------------------+
mysql> SELECT unhex('E298BC');
+-----------------+
| unhex('E298BC') |
+-----------------+
| ☼               |
+-----------------+

Is '☼' what you were expecting before 'STICKY'? You had "double encoding"; it took 2 steps to decode it.

3
  • how do i get the hex for the text in the db?? Feb 24, 2015 at 21:23
  • is it really UTF8 vs latin1?? I thought I had tried conversions from unicode to ANSI and got similar results... what are the differences?? edited my question to include the hex output. thanks! Feb 25, 2015 at 0:59
  • 2
    Unicode is a specification for characters; utf8 (and utf16 and utf32) are ways to express it in computer bytes. ASCII (not ANSI) is a 7-bit encoding (128 codes) that works for English. latin1 is an 8-bit encoding that covers most Western European languages. My charcoll blog discusses this more. Minor variants of latin1 go by a number of different names.
    – Rick James
    Feb 25, 2015 at 1:21

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.