Article Directory
analysis
The reason is that Chinese is not supported, such as the set latin characters, or the inconsistency of encoding and decoding, such as uf8 for the client, latin for the server, etc.
Solution: uniformly set to utf-8 format
. 1. You need to change the configuration file and create a database automatically. utf-8
2, reset the encoding format to utf-8 for the used database, table, and column in the table
Modify the configuration file
Find the myini file in the mysql directory.
If the file is on the c drive, copy it to the desktop and modify it. Otherwise, the c drive will not be protected from modification. You can replace it after
modification. There are two modifications, the client code and the server code
(Note: collation is Sorting method)
Then restart the server, enter the following command in the administrator's cmd to
view the modified mysql encoding format.
I have modified it, this is the modified
Modify database code, table code, column code in table
1. Query the database encoding format first.
If it is not utf8, you can use the following command to modify
ALTER DATABASE 数据库
DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci
or
2. Modify the table encoding format The encoding format of the
query table
show create table tablename (database name. table name);
you can see The output table encoding format is utf8, the column encoding is latin1, and the column does not support Chinese.
If the table encoding is not utf8, you can modify it as follows:
ALTER TABLE tbl_name CONVERT TO CHARACTER SET character_name [COLLATE …] (Note: This sentence sets the default character set of the table and all The character column (CHAR, VARCHAR, TEXT) is changed to a new character set:) For
example, ALTER TABLE web_user.user CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
The query is as follows:
latin disappeared, Chinese is supported, and all encodings are consistent.
If you modify the character set of a field
ALTER TABLE tbl_name CHANGE c_name c_name CHARACTER SET character_name [COLLATE …]; For
example: ALTER TABLE web_user.user CHANGE title title VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_general_ci;
If still unsuccessful, delete and rebuild the data table can be considered.
Attachment:
If you only modify the default character set of the table
ALTER TABLE tbl_name DEFAULT CHARACTER SET character_name [COLLATE...];
such as: ALTER TABLE logtest SET utf8 COLLATE DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
View the field code:
SHOW FULL COLUMNS FROM tbl_name;