1.mysql配置文件地址
cd /etc/mysql/my.cnf
2.在[mysqld]在下方添加以下代码
[mysqld] init_connect='SET collation_connection = utf8_unicode_ci' init_connect='SET NAMES utf8' character-set-server=utf8 collation-server=utf8_unicode_ci skip-character-set-client-handshake
3.重启mysql服务
sudo service mysql restart
4.检测字符集是否更新成utf8.
进入mysql,mysql -u root -p,输入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/ | +--------------------------+----------------------------+