在 MariaDB 服务器中设置 UTF-8 会忽略 character_set_system

Setting UTF-8 in MariaDB server ignores character_set_system

我有以下 Dockerfile MariaDB 服务器的定义文件:

version: "3.8"

...

services:
  database:
    command: ["mysqld", "--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci"]
    container_name: mariadb
    environment:
      MARIADB_DATABASE: sample_database
      MARIADB_INITDB_SKIP_TZINFO: "true"
      MARIADB_PASSWORD_FILE: /run/secrets/mariadb_user_password
      MARIADB_ROOT_PASSWORD_FILE: /run/secrets/root_user_password
      MARIADB_USER: mariadb
      TZ: "Etc/UTC" # https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
    image: docker.io/library/mariadb:10.6-focal # https://hub.docker.com/_/mariadb/
    networks:
      - global-network
    ports:
      - "3306:3306"
    restart: on-failure
    secrets:
      - mariadb_user_password
      - root_user_password
    stdin_open: true
    tty: true
    volumes:
      - "database-volume:/var/lib/mysql"

我不太精通这个话题,但如果我想检查服务器使用的字符集和排序规则集,我通常会执行这些查询:

> show variables like 'char%';
+------------------------+--------------------------+
|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    |utf8mb3                   |
|character_sets_dir      |/usr/share/mysql/charsets/|
+------------------------+--------------------------+


> show variables like 'collation%';
+--------------------+------------------+
|Variable_name       |Value             |
+--------------------+------------------+
|collation_connection|utf8mb4_unicode_ci|
|collation_database  |utf8mb4_unicode_ci|
|collation_server    |utf8mb4_unicode_ci|
+--------------------+------------------+

我的理解是我的设置:--character-set-server=utf8mb4--collation-server=utf8mb4_unicode_ci 是将字符集和排序规则都设置为 UTF-8 的正确设置。

现在我的问题是:如何摆脱 character_set_systemutf8mb3 值?它应该与其他值一起设置为 utf8mb4 — 或者这就是我的想法 ;)

有什么正确设置的线索吗?

I would like to avoid using any configuration file(s) (like my.cnf) since I'm using the stock Docker image without any modifications.

我在 MariaDB 10.6.5 中遇到了类似的问题,我试图从 AWS 加载转储并遇到此错误:

ERROR 1253 (42000) at line 26: COLLATION 'utf8mb3_general_ci' is not valid for CHARACTER SET 'utf8mb4'

我的配置如下所示:

MariaDB [(none)]> SHOW VARIABLES LIKE '%char%';
+--------------------------+----------------------------+
| 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     | utf8mb3                    |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

并且根据此页面 https://mariadb.com/kb/en/old-mode/ 我必须在 /etc/mysql/mariadb.conf.d/50-server.cnf

中将 old-mode 设置为空

old-mode=

因此它从

MariaDB [(none)]> SHOW VARIABLES LIKE '%old%';
+------------------------------------------+-----------------+
| Variable_name                            | Value           |
+------------------------------------------+-----------------+
| old_mode                                 | UTF8_IS_UTF8MB3 |
+--------------------------+---------------------------------+

MariaDB [(none)]> SHOW VARIABLES LIKE '%old%';
+------------------------------------------+-----------------+
| Variable_name                            | Value           |
+------------------------------------------+-----------------+
| old_mode                                 |                 |
+--------------------------+---------------------------------+

所以我设法加载了 SQL 转储,即使 character_set_system 仍然显示 utf8mb3

HTH 某人。

character_set_system 指定将用于存储标识符和其他内部信息的字符集。

它是3byte utf8,除非你改变来源并重新编译MariaDB,否则你不能改变它。

从10.6开始,utf8映射为utf8mb3(以后的版本会映射为utf8mb4)。参见 MDEV-8334