Open2

DatastreamでAWS RDS のMySQLで collationによりmysql.rds_set_configurationできない問題

鶴仙人鶴仙人

Google Cloud のDatastreamを使ってAWS のRDS のMySQLへ接続したい。
その手順にあるコマンド実行ができない。

バイナリログの保持期間を設定する at Amazon RDS MySQL データベースを構成する
https://cloud.google.com/datastream/docs/configure-amazon-rds-mysql?hl=ja#rds-set-binary-log

対象コマンドは call mysql.rds_set_configuration('binlog retention hours', 168);

実際の結果

mysql> call mysql.rds_set_configuration('binlog retention hours', 168);
ERROR 1267 (HY000): Illegal mix of collations (utf8mb4_0900_ai_ci,IMPLICIT) and (utf8mb4_general_ci,IMPLICIT) for operation '='

原因

collation。

  • MySQLのcollationをutf8mb4_general_ciで統一している
  • ストアドプロシージャである mysql.rds_set_configurationmysql.rds_configurationを参照し、比較している
  • その比較するカラムのcollationが utf8mb4_0900_ai_ci である
  • そのためストアドプロシージャ内部でutf8mb4_general_ciutf8mb4_0900_ai_ciを比較しており、エラー
  • コマンドラインで実行される文字列がutf8mb4_general_ciで、比較するテーブルカラムがutf8mb4_general_ciなのでエラーになっている、と理解している

解決方法

探し中。

わかっていること

現在、RDSのパラメータグループ 内の init_connect の値でset default_collation_for_utf8mb4=utf8mb4_general_ci; をパラメータグループで設定している。
これを削除すれば、call mysql.rds_set_configuration('binlog retention hours', 168); を実行できる。

init_connect
https://dev.mysql.com/doc/refman/8.0/ja/server-system-variables.html#sysvar_init_connect

5.1.8 サーバーシステム変数: default_collation_for_utf8mb4
https://dev.mysql.com/doc/refman/8.0/ja/server-system-variables.html#sysvar_default_collation_for_utf8mb4

やりたいこと

default_collation_for_utf8mb4の変更は影響範囲がおおきい。
1回コマンドを実行で、mysql.rds_configuration の値を更新できればいいので回避策を探し中

鶴仙人鶴仙人

内容確認用コマンドメモ

mysql.rds_set_configurationの内容確認

SHOW CREATE PROCEDURE mysql.rds_set_configuration \G;

mysql.rds_configurationのカラム構造確認

SHOW FULL COLUMNS FROM mysql.rds_configuration;

mysql.rds_configurationのテーブル内容の確認

select * from mysql.rds_configuration;

変数確認

show variables like '%collation%';