编辑文件/etc/my.cnf, 在[mysqld]标签下添加内容如下:

[root@localhost ~]# vi /etc/my.cnf

[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake

编辑文件/etc/my.cnf.d/client.cnf, 在[client]中添加内容如下:

[root@localhost ~]# vi /etc/my.cnf.d/client.cnf

[client]
default-character-set=utf8

编辑文件/etc/my.cnf.d/mysql-clients.cnf, 在[mysql]中添加内容如下:

[root@localhost ~]# vi /etc/my.cnf.d/mysql-clients.cnf

[mysql]
default-character-set=utf8

全部配置完成, 重启mariadb

systemctl restart mariadb

进入MariaDB查看字符集

MariaDB [(none)]> show variables like "%character%";show variables like "%collation%";
+--------------------------+----------------------------+
| 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/ |
+--------------------------+----------------------------+
8 rows in set (0.03 sec)

+----------------------+-----------------+
| Variable_name        | Value           |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database   | utf8_unicode_ci |
| collation_server     | utf8_unicode_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)