数据库查询乱码
当查询出来的字符乱码时。
方法1:查询前设置
mysql> show variables like'%char%';
+--------------------------+-------------------------------------------------+
| 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.01 sec)
mysql> set character_set_results=utf8;
Query OK, 0 rows affected (0.01 sec)
mysql> show variables like'%char%';
+--------------------------+-------------------------------------------------+
| Variable_name | Value |
+--------------------------+-------------------------------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
+--------------------------+-------------------------------------------------+
7 rows in set (0.01 sec)
方法2:直接修改MySQL的配置文件