1 首先在linux中输入, mysql -u用户名 -p密码,进入mysql命令窗口
2 输入 show variables like 'character%';
看是否是utf8编码:
+--------------------------+--------------------------------+
| Variable_name | Value |
+--------------------------+--------------------------------+
| character_set_client | gbk |
| character_set_connection | gbk |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | gbk |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | D:\xampp\mysql\share\charsets\ |
+--------------------------+--------------------------------+
8 rows in set (0.05 sec)
以上输出说明你的数据库编码为gbk
2 修改my.cnf文件
找到客户端配置[client] 在下面添加
default-character-set=utf8 默认字符集为utf8
在找到[mysqld] 添加
default-character-set=utf8 默认字符集为utf8
修改好后,重新启动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 | D:\xampp\mysql\share\charsets\ |
+--------------------------+--------------------------------+
8 rows in set (0.05 sec)
以上输出证明你修改成功。