The default character set and collation in MySQL 8 is utf8mb4 and utf8mb4_0900_ai_ci, see https://dev.mysql.com/doc/refman/8.0/en/charset-server.html.
However, based on mysql_collations table, the default collation for the character set utf8mb4 is utf8mb4_general_ci.
SELECT * FROM mysql_collations WHERE `Charset` = 'utf8mb4' ORDER BY `Id`;
+------+------------------------------+---------+---------+
| Id | Collation | Charset | Default |
+------+------------------------------+---------+---------+
| 45 | utf8mb4_general_ci | utf8mb4 | Yes |
| 46 | utf8mb4_bin | utf8mb4 | |
| 224 | utf8mb4_unicode_ci | utf8mb4 | |
| 225 | utf8mb4_icelandic_ci | utf8mb4 | |
| 226 | utf8mb4_latvian_ci | utf8mb4 | |
| 227 | utf8mb4_romanian_ci | utf8mb4 | |
| 228 | utf8mb4_slovenian_ci | utf8mb4 | |
| 229 | utf8mb4_polish_ci | utf8mb4 | |
| 230 | utf8mb4_estonian_ci | utf8mb4 | |
| 231 | utf8mb4_spanish_ci | utf8mb4 | |
| 232 | utf8mb4_swedish_ci | utf8mb4 | |
| 233 | utf8mb4_turkish_ci | utf8mb4 | |
| 234 | utf8mb4_czech_ci | utf8mb4 | |
| 235 | utf8mb4_danish_ci | utf8mb4 | |
| 236 | utf8mb4_lithuanian_ci | utf8mb4 | |
| 237 | utf8mb4_slovak_ci | utf8mb4 | |
| 238 | utf8mb4_spanish2_ci | utf8mb4 | |
| 239 | utf8mb4_roman_ci | utf8mb4 | |
| 240 | utf8mb4_persian_ci | utf8mb4 | |
| 241 | utf8mb4_esperanto_ci | utf8mb4 | |
| 242 | utf8mb4_hungarian_ci | utf8mb4 | |
| 243 | utf8mb4_sinhala_ci | utf8mb4 | |
| 244 | utf8mb4_german2_ci | utf8mb4 | |
| 245 | utf8mb4_croatian_mysql561_ci | utf8mb4 | |
| 246 | utf8mb4_unicode_520_ci | utf8mb4 | |
| 247 | utf8mb4_vietnamese_ci | utf8mb4 | |
| 255 | utf8mb4_0900_ai_ci | utf8mb4 | |
| 256 | utf8mb4_de_pb_0900_ai_ci | utf8mb4 | |
| 257 | utf8mb4_is_0900_ai_ci | utf8mb4 | |
| 258 | utf8mb4_lv_0900_ai_ci | utf8mb4 | |
| 259 | utf8mb4_ro_0900_ai_ci | utf8mb4 | |
| 260 | utf8mb4_sl_0900_ai_ci | utf8mb4 | |
| 261 | utf8mb4_pl_0900_ai_ci | utf8mb4 | |
| 262 | utf8mb4_et_0900_ai_ci | utf8mb4 | |
| 263 | utf8mb4_es_0900_ai_ci | utf8mb4 | |
| 264 | utf8mb4_sv_0900_ai_ci | utf8mb4 | |
| 265 | utf8mb4_tr_0900_ai_ci | utf8mb4 | |
| 266 | utf8mb4_cs_0900_ai_ci | utf8mb4 | |
| 267 | utf8mb4_da_0900_ai_ci | utf8mb4 | |
| 268 | utf8mb4_lt_0900_ai_ci | utf8mb4 | |
| 269 | utf8mb4_sk_0900_ai_ci | utf8mb4 | |
| 270 | utf8mb4_es_trad_0900_ai_ci | utf8mb4 | |
| 271 | utf8mb4_la_0900_ai_ci | utf8mb4 | |
| 273 | utf8mb4_eo_0900_ai_ci | utf8mb4 | |
| 274 | utf8mb4_hu_0900_ai_ci | utf8mb4 | |
| 275 | utf8mb4_hr_0900_ai_ci | utf8mb4 | |
| 277 | utf8mb4_vi_0900_ai_ci | utf8mb4 | |
| 278 | utf8mb4_0900_as_cs | utf8mb4 | |
| 279 | utf8mb4_de_pb__0900_as_cs | utf8mb4 | |
| 280 | utf8mb4_is_0900_as_cs | utf8mb4 | |
| 281 | utf8mb4_lv_0900_as_cs | utf8mb4 | |
| 282 | utf8mb4_ro_0900_as_cs | utf8mb4 | |
| 283 | utf8mb4_sl_0900_as_cs | utf8mb4 | |
| 284 | utf8mb4_pl_0900_as_cs | utf8mb4 | |
| 285 | utf8mb4_et_0900_as_cs | utf8mb4 | |
| 286 | utf8mb4_es_0900_as_cs | utf8mb4 | |
| 287 | utf8mb4_sv_0900_as_cs | utf8mb4 | |
| 288 | utf8mb4_tr_0900_as_cs | utf8mb4 | |
| 289 | utf8mb4_cs_0900_as_cs | utf8mb4 | |
| 290 | utf8mb4_da_0900_as_cs | utf8mb4 | |
| 291 | utf8mb4_lt_0900_as_cs | utf8mb4 | |
| 292 | utf8mb4_sk_0900_as_cs | utf8mb4 | |
| 293 | utf8mb4_es_trad_0900_as_cs | utf8mb4 | |
| 294 | utf8mb4_la_0900_as_cs | utf8mb4 | |
| 296 | utf8mb4_eo_0900_as_cs | utf8mb4 | |
| 297 | utf8mb4_hu_0900_as_cs | utf8mb4 | |
| 298 | utf8mb4_hr_0900_as_cs | utf8mb4 | |
| 300 | utf8mb4_vi_0900_as_cs | utf8mb4 | |
| 303 | utf8mb4_ja_0900_as_cs | utf8mb4 | |
| 304 | utf8mb4_ja_0900_as_cs_ks | utf8mb4 | |
| 305 | utf8mb4_0900_as_ci | utf8mb4 | |
| 306 | utf8mb4_ru_0900_as_ci | utf8mb4 | |
| 307 | utf8mb4_ru_0900_as_cs | utf8mb4 | |
| 608 | utf8mb4_croatian_ci | utf8mb4 | |
| 609 | utf8mb4_myanmar_ci | utf8mb4 | |
| 610 | utf8mb4_thai_520_w2 | utf8mb4 | |
| 1069 | utf8mb4_general_nopad_ci | utf8mb4 | |
| 1070 | utf8mb4_general_nopad_bin | utf8mb4 | |
| 1248 | utf8mb4_unicode_nopad_ci | utf8mb4 | |
| 1270 | utf8mb4_unicode_520_nopad_ci | utf8mb4 | |
+------+------------------------------+---------+---------+
I have certain applications which automatically executes SET NAMES 'utf8mb4' when establishing new connections to the proxy server.
As a result, the collation_connection becomes utf8mb4_general_ci instead of utf8mb4_0900_ai_ci.
show session variables like '%collation%';
+-------------------------------+--------------------+
| Variable_name | Value |
+-------------------------------+--------------------+
| collation_connection | utf8mb4_general_ci |
| collation_database | utf8mb3_general_ci |
| collation_server | utf8mb4_0900_ai_ci |
| default_collation_for_utf8mb4 | utf8mb4_0900_ai_ci |
+-------------------------------+--------------------+
This causes SQL queries with string comparisons to complain about collation mismatches:
Error Code: 1267. Illegal mix of collations (utf8mb4_0900_ai_ci, COERCIBLE) and (utf8mb4_general_ci, COERCIBLE) for operation '=' 0.079 sec
I attempted to configure some global variables, but none of them seemed to work. I believe that when SET NAMES 'utf8mb4' is executed, the default collation used is determined by the settings in the mysql_collations table.
select * from global_variables where variable_name in ('mysql-default_charset', 'mysql-default_collation_connection');
+------------------------------------+--------------------+
| variable_name | variable_value |
+------------------------------------+--------------------+
| mysql-default_charset | utf8mb4 |
| mysql-default_collation_connection | utf8mb4_0900_ai_ci |
+------------------------------------+--------------------+
I am currently using the latest version of ProxySQL.
The default character set and collation in MySQL 8 is
utf8mb4andutf8mb4_0900_ai_ci, see https://dev.mysql.com/doc/refman/8.0/en/charset-server.html.However, based on
mysql_collationstable, the default collation for the character setutf8mb4isutf8mb4_general_ci.I have certain applications which automatically executes
SET NAMES 'utf8mb4'when establishing new connections to the proxy server.As a result, the collation_connection becomes
utf8mb4_general_ciinstead ofutf8mb4_0900_ai_ci.This causes SQL queries with string comparisons to complain about collation mismatches:
I attempted to configure some global variables, but none of them seemed to work. I believe that when
SET NAMES 'utf8mb4'is executed, the default collation used is determined by the settings in themysql_collationstable.I am currently using the latest version of ProxySQL.