First analysis of the cause of MySQL Chinese garbled:
1. Latin encoding used when building the table
2, the connection database encoding is not specified
3, the write has been garbled (this situation needs to check the source data itself)
Solution Summary: 1. Specify the encoding when creating the library:
Create Database default
2. Modify the encoding of the library:
ALTER DATABASE DEFAULT CHARACTER SET UTF8 COLLATE utf8_bin
3. Modify the encoding of the table:
ALTER TABLE DEFAULT CHARACTER SET
4. Modify the encoding of the field:
ALTER TABLE VARCHAR $ CHARACTER SET not NULL
is to change the field encoding of DD in the MySQL database tablename table to be UTF8
Diagnostic process:
1, SHOW CREATE TABLE testtable; To view the encoding of the current table using the Build table statement if it is a Latin Latin encoding, you can use the
ALTER DATABASE DEFAULT CHARACTER SET
Encoding of the Change table
2. Use the Show create TABLE command again to view the table encoding
If the encoding in the current column is found to be incorrect, use the
ALTER TABLE VARCHAR $ CHARACTER SET not NULL
To encode more Yi dd this column
3, if it is still correct, then check your code in the connection method is correct
Jdbc:mysql://localhost:3306/Test?useunicode=true& characterencoding=UTF-8
Here I am a Java connection, which specifies the encoding of the connection Utf-8
It should be all right here.
4. Modify the system default encoding
Mysql>SHOW VARIABLES like 'character%'; MySQL> SETCharacter_set_client=UTF8; MySQL> SETCharacter_set_connection=UTF8; MySQL> SETCharacter_set_database=UTF8; MySQL> SETCharacter_set_results=UTF8; MySQL> SETCharacter_set_server=UTF8; MySQL> SETCollation_connection=UTF8; MySQL> SETCollation_database=UTF8; MySQL> SETCollation_server=UTF8;
Reference article:
1, http://www.2cto.com/database/201307/227538.html
2, Http://zhidao.baidu.com/link?url=WtACC0jMIsOAk6eX6kJk8qjQhga28VgsYpNPY4Oc9sWH5fgU2OQm1An-IGiV4yZ-PE80VJ5ZB-YxrAVW3Jo8ua
Summary--fix MySQL Chinese garbled