用Mysql客户端查询发现乱码:
mysql> select *from user;+----+------------+----------+------------+-----------+
| id | nickname | password | first_name | last_name |
+----+------------+----------+------------+-----------+
| 1 | chaoliu | 321 | chao | liu |
| 3 | micro | 123 | bill | gates |
| 5 | helloworld | 123 | hello | world |
| 7 | ?? | 123 | ? | ? |
+----+------------+----------+------------+-----------+
4 rows in set (0.00 sec)
上网搜索之后,发现需要改一下charactor_set_results,改为utf8或者gb2312(要根据shell客户端设置的编码)
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 | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /home/work/.jumbo/share/mysql/charsets/ |
+--------------------------+-----------------------------------------+
8 rows in set (0.00sec)
mysql> set character_set_results=utf8;
Query OK,0 rows affected (0.00sec)
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 | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /home/work/.jumbo/share/mysql/charsets/ |
+--------------------------+-----------------------------------------+
8 rows in set (0.01 sec)
这时候,中文就可以正常查看了。
mysql> select *from user;+----+------------+----------+------------+-----------+
| id | nickname | password | first_name | last_name |
+----+------------+----------+------------+-----------+
| 1 | chaoliu | 321 | chao | liu |
| 3 | micro | 123 | bill | gates |
| 5 | helloworld | 123 | hello | world |
| 7 | 你好 | 123 | 中 | 文 |
+----+------------+----------+------------+-----------+
4 rows in set (0.00 sec)
原文:http://www.cnblogs.com/charlesblc/p/5973488.html