数据库-mysql中文显示问题
一:在mysql 下面查看带中文的记录显示乱码
mysql> select * from role; +----+------+ | id | name | +----+------+ | 1 | ?? | +----+------+ 1 row in set (0.00 sec)
解决办法:
1)查看编码:show variables like 'char%';
character_set_results | latin1 显示为拉丁文
2)设置编码:set character_set_results=utf8;
mysql> select * from role;
+----+------+
| id | name |
+----+------+
| 1 | ?? |
+----+------+
1 row in set (0.00 sec)
mysql> show variables like 'char%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
mysql> set character_set_results=utf8;
Query OK, 0 rows affected (0.00 sec)
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from role;
+----+--------+
| id | name |
+----+--------+
| 1 | 讲师 |
+----+--------+
1 row in set (0.00 sec)