命令行窗口查询mysql表数据中文乱码解决办法

之所以会显示乱码,就是因为MySQL客户端输出窗口显示中文时使用的字符编码不对造成的,可以使用如下的命令查看输出窗口使用的字符编码 show variables like ‘char%’;

mysql> show variables like 'char%';
+--------------------------+-----------------------------+
| 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     | utf8                        |
| character_set_system     | utf8                        |
| character_sets_dir       | D:\mysql5.5\share\charsets\ |
+--------------------------+-----------------------------+
8 rows in set (0.00 sec)

解决办法:
可以看到,现在是使用utf8字符编码来显示中文数据的,但是因为操作系统是中文操作系统,默认使用的字符集是GB2312,所以需要把输出窗口使用的字符编码改成gb2312才能够正常显示中文。使用如下的命令设置输出窗口使用的字符编码:

set character_set_results=gb2312;

mysql> show variables like 'char%';
+--------------------------+-----------------------------+
| Variable_name            | Value                       |
+--------------------------+-----------------------------+
| character_set_client     | utf8                        |
| character_set_connection | utf8                        |
| character_set_database   | utf8                        |
| character_set_filesystem | binary                      |
| character_set_results    | gb2312                      |
| character_set_server     | utf8                        |
| character_set_system     | utf8                        |
| character_sets_dir       | D:\mysql5.5\share\charsets\ |
+--------------------------+-----------------------------+
8 rows in set (0.00 sec)

改完之后,再查看显示表数据:

mysql> select url,name from websites;
+---------------------------+----------+
| url                       | name     |
+---------------------------+----------+
| https://www.taobao.com/   | 淘宝        |
| http://www.runoob.com     | 菜鸟教程        |
| http://weibo.com/         | 微博        |
| https://www.facebook.com/ | Facebook |
| https://www.google.cm/    | Google   |
+---------------------------+----------+
5 rows in set (0.00 sec)
相关推荐
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页