LoginSignup
2
2

More than 3 years have passed since last update.

ERROR 1267 (HY000): Illegal mix of collationsとなった時の対応方法

Posted at
  • 環境 : MySQL 8.0.20

事象:変数を条件に使ったSQLを書いたファイルを実行したら怒られた

hoge.sql
SET @no = "0531";
select * from person_table WHERE person_no = @no;
mysql> source hoge.sql
Query OK, 0 rows affected (0.01 sec)

ERROR 1267 (HY000): Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_0900_ai_ci,IMPLICIT) for operation '='

原因 : 照合順序がカラムと変数で不一致だから

対応 : 変数をSETするときに照合順序も指定する

hoge.sql
SET @no = "0531" COLLATE utf8mb4_general_ci;
select * from person_table WHERE person_no = @no;
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2