Today, we have a unique problem with Mysql garbled characters. In the past, we had to solve it in a hurry. This time I really can't stand it. Every time, it's all confused. I decided to make a good exploration and read a lot of materials and blogs before I understood it. Record it first. If there is any error, please correct it. 1. Mysql supports multiple character sets only after Mysql 4.0. This problem only occurs after 4.0. The encoding conversion rule is to convert the encoding from "client encoding" to "server encoding" during data input ", during output, data is converted from "server-side encoding" to "client encoding ". MySQL character set processing is like this: 1. Send a request.
1) the client sends a request to the server.
2) The server converts the requested data from the client character set (character_set_client) to the server connection character set (character_set_connection ).
3) The server then checks the character set of the storage area (table, column,
Then, convert the data from the character set character_set_connection to the character set of the storage area (table, column), and then store or query the data.
2. Return the request.
1) The server converts the character set of the storage area (table, column) to the character_set_connection character set ).
2) convert the server connection character set (character_set_connection) to the result character set (character_set_results) and send it to the client.
First, let's take a look at mysql> status;
We can see the settings of the four character sets. 1. Changing the encoding in the my. ini file can change all character sets. 2. set names "uf8" can change the two character sets of Client conn. 3. The encoding set during database creation can change the database. Now that I know the principle, I began to solve the problem today. 1. Chinese is displayed normally elsewhere. However, garbled characters cannot be displayed in CMD. First, I set my. ini to set all character sets to utf8. Personally, utf8 tends to be standard. The database is set to utf8when it is created. However, the command output by CMD is garbled. This is because CMD. That is, dos in windows is not supported by utf8. Therefore, I can convert the encoding method from output to client to GBK. That is, set names gbk. OK. Author JavaNote