MySQL Chinese garbled solutions, mysql Chinese garbled
Test environment: the server and client are both win7. the MySql database and table character set are UTF-8, and the field character set is consistent with the table. 1. Solve the garbled problem when using the mysql Command for operations.
(1) set the current Character Set
Set names gbk
(2) Modify parameters of a Single Character Set
Run the show variables like 'Char % 'command to view all character set variables.
+ -------------------------- + ---------------------------------------- +
| Variable_name | Value |
+ -------------------------- + ---------------------------------------- +
| Character_set_client | utf8 |
| Character_set_connection | utf8 |
| Character_set_database | utf8 |
| Character_set_filesystem | binary |
| Character_set_results | utf8 |
| Character_set_server | latin1 |
| Character_set_system | utf8 |
| Character_sets_dir | D :\ mysql-5.6.25-winx64 \ share \ charsets \ |
+ -------------------------- + ---------------------------------------- +
Modify a single character set:
Set character_set_results = gbk
Note: the parameters set in this method are invalid after the server is restarted.
2. troubleshooting of garbled Characters During mysqldump Export (1) There are two export cases: export table structure and data.
Export the entire table:
Mysqldump-uroot-p [databasename] -- table [tablename]
Export only the table structure:
Mysqldump-uroot-p [databasename] -- table [tablename]-d
(2) Experiment
After testing, no matter how the -- default-character-set parameter is set during table structure export in the console, the Chinese characters in the field comment cannot be displayed normally. The command is as follows:
Mysqldump-uroot-p -- default-character-set = gbk test -- table t_data
However, Chinese characters in table data can be displayed normally (by setting-- Default-character-set = gbk).
However, if exported as a file, it can be displayed normally. The command example is as follows:
Mysqldump-uroot-p -- default-character-set = gbk mydb -- table t_data-d> t_data. SQL
Interestingly, no matter-- Default-character-setSet the value (gbk, utf8, latin1) to be displayed normally. garbled code is displayed on the console and has a certain relationship with the console itself.
(3) Summary
In the Console environment, the Chinese field annotations in the table structure are always not displayed normally, and the Chinese field annotations are always displayed normally (open with UltraEdit) when output to files using pipelines ).
You must set parameters in table data.-- Default-character-set = gbkTo control the normal output of Chinese characters, including console display or output to files using pipelines.
That is to say-- Default-character-set = gbkOnly the encoding of the table data takes effect. The Chinese in the table structure field comment is invalid.
Refer:
1. view the character set used to create a table:
Show create table [tableName]
2. view the character set used by the table field:
Show full columns from [tableName]
3. View tables
Show tables;
4. View table information
Desc [tablename]
5. view the database
Show databases;
6. view database information
Show create database test;
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.