将MariaDB的字符编码设置为utf8mb4
Before revision. (修正之前)
MariaDB [stock]> SHOW VARIABLES LIKE 'character_set%';
+--------------------------+------------------------------+
| Variable_name | Value |
+--------------------------+------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 ★ |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mariadb/charsets/ |
+--------------------------+------------------------------+
8 rows in set (0.003 sec)
MariaDB [stock]> SHOW VARIABLES LIKE 'collation%';
+----------------------+--------------------+
| Variable_name | Value |
+----------------------+--------------------+
| collation_connection | utf8_general_ci |
| collation_database | utf8mb4_general_ci |
| collation_server | latin1_swedish_ci ★|
+----------------------+--------------------+
3 rows in set (0.001 sec)
对服务器端进行修正
打开/etc/my.cnf.d/mariadb-server.cnf文件。
[mysqld]
character-set-server=utf8mb4
客户端修正
打开/etc/my.cnf.d/client.cnf文件,进入编辑模式。
[client]
default-character-set=utf8mb4
重新启动
systemctl restart mariadb
修订以后
MariaDB [stock]> SHOW VARIABLES LIKE 'character_set%';
+--------------------------+------------------------------+
| Variable_name | Value |
+--------------------------+------------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 ★ |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mariadb/charsets/ |
+--------------------------+------------------------------+
8 rows in set (0.001 sec)
+----------------------+--------------------+
| Variable_name | Value |
+----------------------+--------------------+
| collation_connection | utf8mb4_general_ci |
| collation_database | utf8mb4_general_ci |
| collation_server | utf8mb4_general_ci |
+----------------------+--------------------+
3 rows in set (0.001 sec)