修改两个文件:
①./etc/mysql/conf.d/mysql.cnf在[mysql]后添加:
[mysql]
default-character-set = utf8
②./etc/mysql/mysql.conf.d/mysqld.cnf在相应位置添加:
[client] // 默认没有,添加
default-character-set=utf8
[mysqld]
character-set-server = 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 | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
如果显示这样就没问题了,另外,要重新建数据库哦,旧的数据库和表什么的均还是出现乱码的。