MYSQL乱码问题

MYSQL乱码问题




mysql> use  demodb;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql>

mysql> show variables like 'character\_set\_%';
+--------------------------+--------+
| Variable_name            | Value  |
+--------------------------+--------+
| character_set_client     | latin1 |
| character_set_connection | latin1 |
| character_set_database   | latin1 |
| character_set_filesystem | binary |
| character_set_results    | latin1 |
| character_set_server     | latin1 |
| character_set_system     | utf8   |
+--------------------------+--------+
7 rows in set (0.00 sec)

mysql> set character_set_client=utf8;
Query OK, 0 rows affected (0.01 sec)

mysql> show variables like 'character\_set\_%';
+--------------------------+--------+
| Variable_name            | Value  |
+--------------------------+--------+
| character_set_client     | utf8   |
| character_set_connection | latin1 |
| character_set_database   | latin1 |
| character_set_filesystem | binary |
| character_set_results    | latin1 |
| character_set_server     | latin1 |
| character_set_system     | utf8   |
+--------------------------+--------+
7 rows in set (0.00 sec)

mysql> select * from project;
+-------+------------+------+--------------+-------------+-----------+----------+--------------+--------+
| ID    | pname      | URL  | LEAD         | DESCRIPTION | pkey      | pcounter | ASSIGNEETYPE | AVATAR |
+-------+------------+------+--------------+-------------+-----------+----------+--------------+--------+
| 10200 | demo       | NULL | aaa      | NULL        | DEMO      |      159 |            2 |  10011 |
| 10300 | demo2      | NULL | bbb | NULL        | DEMOTWO   |        1 |            2 |  10011 |
| 10302 | ??????     |      | ccc      |             | FFF        |        0 |            2 |  10011 |
| 10500 | ????       | NULL | aaa      | NULL        | QQQ       |       11 |            2 |  10011 |
| 10501 | SCRUM-???? | NULL | ddd      | NULL        | SFFF       |       24 |            2 |  10011 |
| 10502 | ??????     | NULL | eee      | NULL        | SSS       |        6 |            2 |  10011 |
| 10504 | ????       | NULL | fff      | NULL        | FINANCING |        2 |            2 |  10011 |
+-------+------------+------+--------------+-------------+-----------+----------+--------------+--------+
7 rows in set (0.00 sec)

mysql>



mysql> set character_set_connection=utf8;
Query OK, 0 rows affected (0.00 sec)

mysql> set character_set_database=utf8;
Query OK, 0 rows affected (0.00 sec)

mysql> set character_set_results=utf8;
Query OK, 0 rows affected (0.00 sec)

mysql> set character_set_server=utf8;
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    | utf8   |
| character_set_server     | utf8   |
| character_set_system     | utf8   |
+--------------------------+--------+
7 rows in set (0.00 sec)

mysql> select * from project;
+-------+--------------------+------+--------------+-------------+-----------+----------+--------------+--------+
| ID    | pname              | URL  | LEAD         | DESCRIPTION | pkey      | pcounter | ASSIGNEETYPE | AVATAR |
+-------+--------------------+------+--------------+-------------+-----------+----------+--------------+--------+
| 10200 | demo               | NULL | aaa      | NULL        | DEMO      |      159 |            2 |  10011 |
| 10300 | demo2              | NULL | bbb | NULL        | DEMOTWO   |        1 |            2 |  10011 |
| 10302 | 实例项目需求 |      | ccc      |             | FFF        |        0 |            2 |  10011 |
| 10500 | 演示项目       | NULL | ddd      | NULL        | QQQ       |       11 |            2 |  10011 |
| 10501 | SCRUM-实例项目 | NULL | eee      | NULL        | SFFF       |       24 |            2 |  10011 |
| 10502 | 正式A需求 | NULL | fff      | NULL        | SSS       |        6 |            2 |  10011 |
| 10504 | 正式T       | NULL | ddd      | NULL        | FINANCING |        2 |            2 |  10011 |
+-------+--------------------+------+--------------+-------------+-----------+----------+--------------+--------+
7 rows in set (0.00 sec)


通过以上过程说明.仅仅通过set character_set_client=utf8;是不能解决乱码问题的.解决乱码问题需要把mysql的服务器编码设置成utf8,同时,创建数据库的时候需要把数据库的编码设置成utf8编码,才能解决mysql数据库查询乱码问题.

如果数据库服务器的编码是utf8,而数据库的编码也是utf8,在客户端查询出现乱码,基本上可以推断是客户端的设置不是utf8编码.

数据库服务编码设置请参见mysql服务端编码设置.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值