[root@centos6-test08 yum.repos.d] # cat /etc/my.cnf
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]
#
# include all files from the config directory
#
!includedir /etc/my .cnf.d // 说明在该配置文件中引入 /etc/my .cnf.d 目录下的配置文件
[root@centos6-test08 yum.repos.d] # ls /etc/my.cnf.d/
enable_encryption.preset mysql-clients.cnf server.cnf
首先是配置文件 /etc/my .cnf.d /server .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 /mysql-clients .cnf,在[mysql]中添加
default-character- set =utf8
最后是重启MariaDB,并登陆MariaDB查看字符集
[root@centos6-test08 yum.repos.d] # /etc/init.d/mysql restart
Shutting down MariaDB.. SUCCESS!
Starting MariaDB.180313 05:47:41 mysqld_safe Logging to '/var/lib/mysql/centos6-test08.err' .
180313 05:47:41 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
SUCCESS!
[root@centos6-test08 yum.repos.d] # mysql -p123456
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.3.5-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
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.001 sec)
+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_unicode_ci |
| collation_database | utf8_unicode_ci |
| collation_server | utf8_unicode_ci |
+----------------------+-----------------+
3 rows in set (0.001 sec)
|