我的mysql是通过xampp安装的,版本号为5.6.24;
linux环境为Ubuntu14.04;
mysql数据库在添加中文条目时,用select* from后显示'???',使用mysql命令show variables like 'char%'查看得:
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /opt/lampp/share/charsets/ |
+--------------------------+----------------------------+其中database及server均为latin编码方式,
百度后说修改/etc/mysql/my.cnf文件,但对于我的环境来说没有用;
偶然发现通过xampp安装的mysql的配置文件(my.cnf)在/opt/lampp/etc中,
然后分别添加
[Client]
default-character-set = utf8
[mysqld]
character-set-server= utf8
大功告成!
mysql> select* from name;
+----+------+------+------------+
| id | xm | xb | csny |
+----+------+------+------------+
| 1 | 成 | 功 | 2333-12-23 |
+----+------+------+------------+
1 row in set (0.00 sec)