最近我从 Rocky Linux 8 @appstream repo 安装了 MariaDB 10.5.9。在将数据库服务器配置为对所有内容都使用 utf8mb4_unicode_ci 后,我的数据库客户端工具遇到了一个奇怪的错误。该错误可在命令行上重现:
$ MariaDB > SELECT user FROM mysql.user WHERE is_role = 'N' ;
ERROR 1267 (HY000): Illegal mix of collations (utf8mb4_unicode_ci,COERCIBLE) and (utf8mb4_general_ci,COERCIBLE) for operation '='
我通过删除并重新创建视图来“修复”错误,这迫使视图使用 utf8mb4_general_ci。
但是,我不明白为什么查询阻塞,当下面的查询使用 utf8mb4_unicode_ci 和 utf8mb4_general_ci 连接排序规则时:
MariaDB > select * from wp_options where option_name = 'N';
Empty set (0.000 sec)
两个数据集都是 utf8mb4_unicode_ci:
MariaDB > show create table wp_options;
+------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table
+------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| wp_options | CREATE TABLE `wp_options` (
`option_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`option_name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
`option_value` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
`autoload` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'yes',
PRIMARY KEY (`option_id`),
UNIQUE KEY `option_name` (`option_name`),
KEY `autoload` (`autoload`)
) ENGINE=InnoDB AUTO_INCREMENT=62383 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci |
+------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.000 sec)
MariaDB > show create view mysql.user;
+------+------------------------------------------------------+----------------------+----------------------+
| View | Create View | character_set_client | collation_connection |
+------+------------------------------------------------------+----------------------+----------------------+
| user | CREATE ALGORITHM=UNDEFINED DEFINER=`mariadb.sys` ... | utf8mb4 | utf8mb4_unicode_ci |
+------+------------------------------------------------------+----------------------+----------------------+
1 row in set (0.001 sec)
MariaDB > SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, COLLATION_NAME FROM INFORMATION_SCHEMA.COLUMNS where TABLE_SCHEMA = 'mysql' ORDER BY TABLE_NAME;
| mysql | user | Create_view_priv | utf8mb4_unicode_ci |
| mysql | user | Repl_client_priv | utf8mb4_unicode_ci |
| mysql | user | Repl_slave_priv | utf8mb4_unicode_ci |
| mysql | user | Reload_priv | utf8mb4_unicode_ci |
| mysql | user | Drop_priv | utf8mb4_unicode_ci |
| mysql | user | Create_priv | utf8mb4_unicode_ci |
| mysql | user | Delete_priv | utf8mb4_unicode_ci |
| mysql | user | Update_priv | utf8mb4_unicode_ci |
| mysql | user | Insert_priv | utf8mb4_unicode_ci |
| mysql | user | Select_priv | utf8mb4_unicode_ci |
| mysql | user | Password | utf8mb4_bin |
| mysql | user | User | utf8_bin |
| mysql | user | Shutdown_priv | utf8mb4_unicode_ci |
| mysql | user | Process_priv | utf8mb4_unicode_ci |
| mysql | user | File_priv | utf8mb4_unicode_ci |
| mysql | user | Execute_priv | utf8mb4_unicode_ci |
| mysql | user | Lock_tables_priv | utf8mb4_unicode_ci |
| mysql | user | Create_tmp_table_priv | utf8mb4_unicode_ci |
| mysql | user | Super_priv | utf8mb4_unicode_ci |
| mysql | user | Show_db_priv | utf8mb4_unicode_ci |
| mysql | user | Alter_priv | utf8mb4_unicode_ci |
| mysql | user | Index_priv | utf8mb4_unicode_ci |
| mysql | user | References_priv | utf8mb4_unicode_ci |
| mysql | user | Grant_priv | utf8mb4_unicode_ci |
| mysql | user | Host | utf8_bin |
+--------------+---------------------------+--------------------------+--------------------+
以下是系统字符集和排序规则:
MariaDB > 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 | utf8 |
| character_sets_dir | /usr/share/mariadb/charsets/ |
+--------------------------+------------------------------+
8 rows in set (0.001 sec)
MariaDB > show variables like '%collat%';
+----------------------+--------------------+
| Variable_name | Value |
+----------------------+--------------------+
| collation_connection | utf8mb4_general_ci |
| collation_database | utf8mb4_unicode_ci |
| collation_server | utf8mb4_unicode_ci |
+----------------------+--------------------+
3 rows in set (0.001 sec)
是什么导致第一个查询失败但第二个查询失败?