When inserting Chinese data into MySQL, there is garbled, as follows:
Mysql> select * from test;
+------+-----------+
| ID | name |
+------+-----------+
| 1 | Phenomena example belong 鍧? |
| 2 | Phenomena phone 檽 traitor? |
| 3 | Lao à size Boss? |
| 4 | Phenomena 嬮 vent traitor? |
| 5 | ACI 嗕 簯 |
| 6 | Jean Taiwan Upsome Lian? |
| 1 | Demo1 |
| 2 | Demo2 |
| 3 | Demo3 |
+------+-----------+
But in the application, it can be a normal reality data
1 Li Xiaofeng
2 Wang Xiaofeng
3 Photos of snow
4 Wang Xuefeng
5 Lu Yun
6 Peach Blossom Girl
1demo1
2demo2
3demo3
In order for the client to display the Chinese correctly, the following encoding set can be modified, as follows:
Enter show variables like ' char% ';
Mysql> Show variables like ' char% ';
+--------------------------+-----------------------------+
| variable_name | Value |
+--------------------------+-----------------------------+
| character_set_client | UTF8 |
| character_set_connection | GBK |
| Character_set_database | GBK |
| Character_set_filesystem | binary |
| Character_set_results | UTF8 |
| Character_set_server | GBK |
| Character_set_system | UTF8 |
| Character_sets_dir | D:\mysql6.0\share\charsets\ |
+--------------------------+-----------------------------+
8 rows in Set (0.00 sec)
You can see that both the Character_set_client and character_set_results codes are UTF8 and now change them to GBK
Mysql> set CHARACTER_SET_CLIENT=GBK;
Query OK, 0 rows Affected (0.00 sec)
Mysql> set CHARACTER_SET_RESULTS=GBK;
Query OK, 0 rows Affected (0.00 sec)
Then use show variables like ' char% '; query
Mysql> Show variables like ' char% ';
+--------------------------+-----------------------------+
| variable_name | Value |
+--------------------------+-----------------------------+
| character_set_client | GBK |
| character_set_connection | GBK |
| Character_set_database | GBK |
| Character_set_filesystem | binary |
| Character_set_results | GBK |
| Character_set_server | GBK |
| Character_set_system | UTF8 |
| Character_sets_dir | D:\mysql6.0\share\charsets\ |
+--------------------------+-----------------------------+
View the contents of the database again
Mysql> select * from test;
+------+--------+
| ID | name |
+------+--------+
| 1 | Li Xiaofeng |
| 2 | Wang Xiaofeng |
| 3 | Zhangxiaoxue |
| 4 | Wang Xuefeng |
| 5 | Lu Yun |
| 6 | Peach Blossom Women |
| 1 | Demo1 |
| 2 | Demo2 |
| 3 | Demo3 |
+------+--------+
9 Rows in Set (0.00 sec)
MySQL Client data garbled problem