数据库项目惊现此景
(不就是个乱码吗,有什么大惊小怪的呢?!)
PS: 数据库 配置文件里的编码格式之前全部改成utf-8了,现在在控制台查数据发现中文的全部是乱码,原因是控制台编码和数据库查询编码不同,转换出问题了。控制台可以改成编码格式是utf-8,试过了,觉得丑,所以去改数据库查询的结果集,把它设置成gbk。
先查一下原来的配置,如下:
mysql> show variables like 'character_set%' ;
+--------------------------+----------------------------------------------------
-----+
| 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 :\Program Files \MySQL \MySQL Server 5.5 \share\chars
ets\ |
+--------------------------+----------------------------------------------------
-----+
8 rows in set (0.00 sec)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
可以看出来全部是utf-8,然后用set character_set_results=’gbk’,如下:
mysql> set character_set _results='gbk' ;
Query OK, 0 rows affected (0.00 sec)
这样就改好了,可以再查询看一下:
mysql> show variables like 'character_set%' ;
+--------------------------+----------------------------------------------------
-----+
| Variable_name | Value
|
+--------------------------+----------------------------------------------------
-----+
| character_set_client | utf8
|
| character_set_connection | utf8
|
| character_set_database | utf8
|
| character_set_filesystem | binary
|
| character_set_results | gbk
|
| character_set_server | utf8
|
| character_set_system | utf8
|
| character_sets_dir | D :\Program Files \MySQL \MySQL Server 5.5 \share\chars
ets\ |
+--------------------------+----------------------------------------------------
-----+
8 rows in set (0.00 sec)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
已经修改好了,再查不会乱码了
其实就两句话:
mysql> show variables like 'character_set%'; //展示原来的配置 mysql> set character_set_results='gbk'; //将其设置为GBK,如果不是GBK进来的亲,麻烦您老自己改为UTF-8
不过GBK进来的,还是靠稍息立正吧。。。