MySQL 查看和修改字符编码

  1. 登录 MySQL 服务器所在 Linux 系统后输入
[root@localhost ~]# mysql -u root -p
  1. 查看字符编码
mysql> showvariables like '%char%';
字符编码

如果character_set_server字符编码不是utf8,对中文的处理会有问题

  1. 修改 MySQL 配置文件里字符编码的设置
    先找到MySQL配置文件的位置,一般是 /etc/my.cnf 或 /usr/my.cnf
[root@localhost ~]# find / -name my.cnf
[root@localhost ~]# vi /etc/my.cnf

在 [mysqld] 下面一行增加

character_set_server = utf8

然后保存退出

  1. 重启 MySQL 服务
[root@localhost ~]# systemctl restart mysql
  1. 再次查看字符编码
[root@localhost ~]# mysql -u root -p
mysql> showvariables like '%char%';
字符编码

如果结果如上图显示,说明字符编码已经成功修改为 utf8

你可能感兴趣的:(MySQL 查看和修改字符编码)