mysql客户端数据乱码问题
往mysql插入中文数据时出现乱码,如下:
mysql> select * from test;
+------+-----------+
| id | name |
+------+-----------+
| 1 | 鐜嬪煿鍧?|
| 2 | 鐜嬫檽宄?|
| 3 | 寮犲皬闆?|
| 4 | 鐜嬮洩宄?|
| 5 | 闄嗕簯 |
| 6 | 妗冭姳濂?|
| 1 | demo1 |
| 2 | demo2 |
| 3 | demo3 |
+------+-----------+
但是在应用程序中却可以正常的现实数据
1李晓峰
2王晓峰
3张小雪
4王雪峰
5陆云
6桃花女
1demo1
2demo2
3demo3
为了在客户端可以正常的显示中文,可以修改下编码集,如下:
输入 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)
可以看到character_set_client 和character_set_results的编码都为utf8,现在把它们都修改为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)
再使用 show variables like ‘char%‘;查询
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\ |
+--------------------------+-----------------------------+
再查看数据库中的内容
mysql> select * from test;
+------+--------+
| id | name |
+------+--------+
| 1 | 李晓峰 |
| 2 | 王晓峰 |
| 3 | 张小雪 |
| 4 | 王雪峰 |
| 5 | 陆云 |
| 6 | 桃花女 |
| 1 | demo1 |
| 2 | demo2 |
| 3 | demo3 |
+------+--------+
9 rows in set (0.00 sec)
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。