1、确认当前编码格式
代码语言:javascript复制 进入mysql shell 窗口 进行查询
查询命令: show variables like 'character_set_%';
mysql> show variables like ‘character_set_%’; ±-------------------------±--------------------------- | Variable_name | Value | ±-------------------------±--------------------------- | character_set_client | latin1 | | character_set_connection | latin1 | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | latin1 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | ±-------------------------±---------------------------
代码语言:javascript复制2、设置mysql各个角色的编码
编辑/etc/my.cnf文件(安装mysql后系统自动添加的),在文件中添加一下内容,最后保存退出
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
character-set-server=utf8
3、重启mysql
/etc/init.d/mysqld restart
4、再次确认编码格式
show variables like 'character_set_%';
mysql> show variables like ‘character_set_%’; ±-------------------------±--------------------------- | 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/ | ±-------------------------±---------------------------