最近遇到mysql中文乱码的问题,更纠结的是在linux环境下,本人对于linux本身就是一片模糊,没办法只能硬着头皮改,
进入到mysql目录下
1.执行./client.sh,
2.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 | /usr/share/mysql/charsets/ |
3.修改 mysql 的配置文件--/etc/my.cnf
4.打开配置文件
5.在[mysqld]下追加:(只在此处添加)
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
注意:此处针对的是mysql的5.7版本,其配置文件下只有[client]和[mysqld]
,没有[mysql] ,之前参考的很多,但是都失败了,特此标注
6.重启mysql服务
./startServer.sh
7登录mysql查询
show variables like 'char%'
+--------------------------+----------------------------+
| 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/ |
+--------------------------+----------------------------+
ok 到此修改成功