You need to convert the MySQL database from Latin1 encoding to utf8 encoding. Some methods searched online are useless.
I found a feasible method multiple times:
0. Download tool navicat for MySQL
1. Export the table structure of the database mysqldump-uuser-p-D dB> dB. SQL
2. Edit dB. SQL and replace Latin1 with utf8.
3. Create a new database newdb and run dB. SQL to create a table.
4. Use navicat for MySQL to connect to the database. Right-click the database table to be exported and select the export wizard.
4. 1. Select the XML file (*. XML) and click Next;
1252. Select All Tables, select the export path for each table in the export to column, click Advanced, and select (ANSI-Latin I );
. Continue to the next step until the end and click Start.
5. Use ue or notepad ++ to open the exported XML file and convert it to UTF-8 without BOM encoding format.
6. Open the import wizard for each table
6. 1. Select the XML file (*. XML) and click Next;
. Select the XML file to be imported and click Next;
. Select the label that indicates a table row as record;
. Continue to the next step until the end and click Start.
The entire conversion process is completed, so the table data is converted normally, including special symbols and single quotes.
Note: I have a table in the format of utf8. First export it with utf8 (default utf8 in step 1). No matter how it is converted, It is garbled.
I noticed later that although the table is encoded as utf8, Latin1 is used by default when storing data in web programs.
Therefore, it is exported as Latin1 and converted successfully.
Note: In fact, webpage Code cannot be converted. <A> </a> is transcoded by XML...
Solution: export the SQL file and execute the SQL file.