Mysql でダンプファイル を生成しようとしたら「Illegal mix of collations」というエラーが表示されました。
その時調べたことをここにメモします。
エラー発生時
パスワード等々で Warning もでている。
$ mysqldump -h hoge -P 3306 -uroot -phogehoge sample --ssl-mode=DISABLED > sample_20240327.dump mysqldump: [Warning] Using a password on the command line interface can be insecure. Warning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transactions, even those that changed suppressed parts of the database. If you don't want to restore GTIDs, pass --set-gtid-purged=OFF. To make a complete dump, pass --all-databases --triggers --routines --events. mysqldump: Error: 'Illegal mix of collations (utf8mb3_general_ci,COERCIBLE) and (utf8mb3_unicode_ci,COERCIBLE) for operation '='' when trying to dump tablespaces
「Illegal mix of collations」とは
互換性のない異なる CHARSET があると発生するみたいです。
今回の場合は「utf8_unicode_ci」 と 「utf8_general_ci」のようです。
解決策
他の照合順序と一致するように変更する必要があるみたいです。
照合順序が不適切な列を探します。
SHOW CREATE TABLE table_name;
各列の順序を変更します。
ALTER TABLE table_name CHANGE col_name data_type CHARACTER SET charset_name COLLATE collation_name;
・
・
・
とやってみたのですが、思う通りにならず。。。
後日再検討...
調査時のコマンドのメモ
mysql> show variables like 'char%' ; +--------------------------+-------------------------------------------+ | Variable_name | Value | +--------------------------+-------------------------------------------+ | character_set_client | utf8mb3 | | character_set_connection | utf8mb3 | | character_set_database | utf8mb3 | | character_set_filesystem | binary | | character_set_results | utf8mb3 | | character_set_server | utf8mb3 | | character_set_system | utf8mb3 | | character_sets_dir | /rdsdbbin/mysql-8.0.35.R1/share/charsets/ | +--------------------------+-------------------------------------------+
mysql> show variables like 'coll%' ; +----------------------+--------------------+ | Variable_name | Value | +----------------------+--------------------+ | collation_connection | utf8mb3_unicode_ci | | collation_database | utf8mb3_unicode_ci | | collation_server | utf8mb3_unicode_ci | +----------------------+--------------------+