云服务器环境:CentOS 7.4
因为服务器配置较低,故使用MySQL5.5
未进行设置前
1、查看字符编码:
mysql> show variables like '%character%';
或
mysql> show variables like 'character_set_%';
结果:
2、对应修改
2.1可通过命令行设置:
set character_set_client = utf8;
set character_set_server = utf8;
set character_set_connection = utf8;
set character_set_database = utf8;
set character_set_results = utf8;
set collation_connection = utf8_general_ci;
set collation_database = utf8_general_ci;
set collation_server = utf8_general_ci;
修改后:
2.2,也可通过修改 my.cnf 文件来修改 utf8 编码
这过程网上教程很多,在这附上一个参考博客地址:
https://blog.csdn.net/u010005180/article/details/53468636
3、最后,重启mysql服务
注意,如果使用命令 service mysql restart
,则会报 Redirecting to /bin/systemctl restart mysql.service
故使用命令 systemctl restart mysql 来重启服务
查看 mysql 服务状态,同样,可用 systemctl status mysql 来查看