Recently I installed MariaDB 10.5.9 from the Rocky Linux 8 @appstream repo. After configuring the database server to use utf8mb4_unicode_ci for everything, I hit a strange error with my database client tool. The error was reproducible on the command line:
$ 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 '='
I "fixed" the error by dropping and re-creating the view, which forced the view to use utf8mb4_general_ci.
However, I do not understand why the query chokes, when the query below which uses utf8mb4_unicode_ci with a utf8mb4_general_ci connection collation does not:
MariaDB > select * from wp_options where option_name = 'N';
Empty set (0.000 sec)
Both datasets are 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 |
+--------------+---------------------------+--------------------------+--------------------+
Here are the system character sets and collations:
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)
What causes the first query to fail but not the second?