当在服务器远程连接mysql服务器的时候,登录后编码方式latin1;接着我在mysql命令窗口修改为utf-8后,再次远程登录,编码方式依然为latin1;
#mysql -h 192.168.1.114 -uroot -p123456
mysql> show variables like '%character%'
-> ;
+--------------------------+----------------------------------+
| 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 | /usr/local/mysql/share/charsets/ |
+--------------------------+----------------------------------+
mysql>select * from table;
idname
1 ???
2android
12 wap
当直接登录mysql服务器,查看其字符编码、mysql的字符集等均为utf-8;
可以确定是当前客户端连接的问题,当使用man mysql中搜索utf-8才发现,原来加入一个字符编码参数(–default-character-set=utf8)才解决的了此问题;
#mysql -h 192.168.1.114 --default-character-set=utf8 -uroot -p123456
mysql> show variables like '%character%';
+--------------------------+----------------------------------+
| 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 | /usr/local/mysql/share/charsets/ |
+--------------------------+----------------------------------+
再查询某个具有中文字符的表数据显示正常;
mysql>select * from table;
idname
1 女生频道
2android
12 wap