进入数据库执行
SET GLOBAL character_set_clinet=utf8;
SET GLOBAL character_set_connection=utf8;
SET GLOBAL character_set_database=utf8;
SET GLOBAL character_set_results=utf8;
SET GLOBAL character_set_server=utf8;
退出数据库,停止数据库服务
systemctl stop mariadb.service
在终端界面中执行
vim /etc/my.cnf
打开my.cnf后,在文件内的[mysqld]下增加如下两行设置:
character_set_server=utf8
init_connect='SET NAMES utf8'
保存退出
启动数据库
systemctl start mariadb.service
进入数据库查看默认字符集
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/ | +--------------------------+----------------------------+