The garbled mysql problem is a headache, sometimes on the console, and sometimes on the service side.
MySQL can refine the character set designation to a database, a table, and a column. Traditional programs do not use such complex configurations when creating databases and data tables. They use default configurations.
(When installing mysql, especially using the integrated environment: for example, if you do not set a password for appserver wampserver, open the console and press enter .)
First, how to query mysql encoding:
Use the command statement:
Mysql> show variables like 'character % ';
Second, to solve the garbled code problem, it may be the encoding problem. You can modify the encoding as follows:
Problem 1: garbled characters are everywhere. The simplest modification method is to modify the character set key value in mysql's my. Ini file:
Default-character-set = utf8
Character_set_server = utf8
The second method is to use the mysql command:
Mysql> SET character_set_client = utf8;
Mysql> SET character_set_connection = utf8;
Mysql> SET character_set_database = utf8;
Mysql> SET character_set_results = utf8;
Mysql> SET character_set_server = utf8;
Mysql> SET collation_connection = utf8;
Mysql> SET collation_database = utf8;
Mysql> SET collation_server = utf8;
Problem 2: generally even if the default character set of the table is set to utf8 and the query is sent through the UTF-8 encoding, you will find that the database is still garbled.
The problem lies in the connection layer. The solution is to execute the following statement before sending the query:
Set names 'utf8 ';
It is equivalent to the following three commands:
SET character_set_client = utf8;
SET character_set_results = utf8;
SET character_set
_ Connection = utf8;
Question 3: I don't know why. After I set all the three character sets on my machine to utf8, the Chinese query results are still garbled, only after character_set_results is set to GBK can Chinese characters be properly displayed from the command line.