# # These two groups are read by the client library # Use it for options that affect all clients, but not the server #
[client] default-character-set = utf8mb4 # 添加此行 # This group is not read by mysql client library, # If you use the same .cnf file for MySQL and MariaDB, # use it for MariaDB-only client options [client-mariadb]
服务端配置
vi /etc/my.cnf.d/server.cnf
# # These groups are read by MariaDB server. # Use it for options that only the server (but not clients) should see # # See the examples of server my.cnf files in /usr/share/mysql/ #
# this is read by the standalone daemon and embedded servers [server] # this is only for the mysqld standalone daemon [mysqld] # 此行开始 character-set-client-handshake = FALSE character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci init_connect='SET NAMES utf8mb4'
# this is only for embedded server [embedded]
# This group is only read by MariaDB-5.5 servers. # If you use the same .cnf file for MariaDB of different versions, # use this group for options that older servers don't understand [mysqld-5.5]
# These two groups are only read by MariaDB servers, not by MySQL. # If you use the same .cnf file for MySQL and MariaDB, # you can put MariaDB-only options here [mariadb] [mariadb-5.5]
重启 Mariadb 使配置生效
systemctl restart mariadb # 如果是mysql需要起相应服务
验证
MariaDB [iyblog_product]>SHOW VARIABLES WHERE Variable_name LIKE'character_set_%'OR Variable_name LIKE'collation%';