Benjamin Zhang

目前就职于中科院计算机网络信息中心,主要兴趣集中在数据库,操作系统,中间件。

【MySQL】Mariadb字符集

24 Sep 2019 » MySQL

Mariadb字符集

如果不设置字符集,可以查看mariadb的字符集的默认设置是latin1

如下命令,查看Mariadb的默认配置:

[root@oradb ~]# /usr/local/mysql/bin/mysqld --verbose --help |grep character-set-server
2019-09-23 16:10:05 0 [Note] Plugin 'FEEDBACK' is disabled.
  -C, --character-set-server=name 
character-set-server                                       latin1

修改Mariadb的字符集为utf8,国际统一标准,配置如下:

[root@oradb ~]# vi /etc/my.cnf 
[mysqld]
datadir=/u01/data/
socket=/tmp/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
character-set-server = utf8

[mysqld_safe]
log-error=/u01/data/mysqld.log
pid-file=/tmp/mysqld.pid

重启服务,如下:

[root@oradb ~]# service mysqld restart

最终,服务器统一为utf8,如下:

[root@oradb ~]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.3.18-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%';
+--------------------------+----------------------------------+
| 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/local/mysql/share/charsets/ |
+--------------------------+----------------------------------+
8 rows in set (0.001 sec)