1、通过 show variables like '%char%';查看MySQL字符集情况
mysql> 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/ |
+--------------------------+----------------------------+
2、修改mysql配置文件
#备份配置文件
sudo cp /etc/mysql/mysql.conf.d/mysqld.cnf /etc/mysql/mysql.conf.d/mysqld.cnf_2
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
# 修改处1:添加以下2行
[client]
default-character-set=utf8
[mysqld]
# 修改处2:添加以下3行
default-storage-engine=INNODB
character-set-server=utf8
collation-server=utf8_general_ci
3、重启mysql
service mysql restart
4、查看字符集
mysql -uroot -p
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/ |
+--------------------------+----------------------------+
---------------------
作者:zheng_lan_fang
来源:CSDN
原文:https://blog.csdn.net/zheng_lan_fang/article/details/77941232
版权声明:本文为博主原创文章,转载请附上博文链接!