mysql encoding problem

1. Check MySQL encoding
  SHOW VARIABLES LIKE 'char%';
because the character set was specified as UTF8 during installation, all encodings are UTF8.
character_set_client: The data you send must be consistent with the encoding specified by the client! ! ! The server will use this code to interpret the data sent
by the client; character_set_connection: This code is consistent with the client! This encoding will not cause garbled characters! When the query statement is executed, the data sent by the client will first be converted into the code specified by the connection. However, as long as the data sent by the client is consistent with the encoding specified by the client, there will be no problem in the conversion;
character_set_database: The default encoding of the database, when the database is created, if the encoding is not specified, the database encoding is used by default;
character_set_server: MySQL The default encoding of the server;
character_set_results: the encoding of the response, that is, the encoding of the query result returned to the client. This means that the client must use the encoding specified by result to decode;

2. Console encoding
Modify character_set_client, character_set_results, and character_set_connection to GBK, and there will be no garbled characters. But in fact only need to modify character_set_client and character_set_results.

The encoding of the console can only be GBK, and cannot be modified to UTF8, which presents a problem. The data sent by the client is GBK, and the character_set_client is UTF8, which means that the client data will be garbled when it reaches the server. Since the encoding of the console cannot be modified, only character_set_client can be modified to GBK.
The data sent by the server to the client is encoded as character_set_result. If it is UTF8, then the console will be garbled when decoding with GBK. Because the console encoding cannot be modified, character_set_result can only be modified to GBK.
Modify the character_set_client variable: set character_set_client=gbk;
Modify the character_set_results variable: set character_set_results=gbk; The

setting code is only valid for the current connection, which means that these two codes must be modified every time you log in to the MySQL prompt, but you can modify them by modifying Configuration file to deal with this problem: Configuration file path: C:\Program Files\MySQL\MySQL Server 5.1\ my.ini


3 MySQL tools
Using MySQL tools will not cause garbled characters, because they will modify character_set_client every time you connect , character_set_results, character_set_connection encoding. In this way, the configuration on my.ini is overwritten, and there will be no garbled characters.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326165023&siteId=291194637