SQL 错误 [1267] [HY000]: Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation '='
1. 主要是因为表中的字符集不统一,先查一下表里的排序规则
select
table_schema,
table_name,
column_name,
character_set_name,
collation_name
from
information_schema.columns
where
collation_name = 'utf8_unicode_ci'
-- collation_name <> 'utf8_unicode_ci' -- 再查下不是utf8_unicode_ci字符集的字段
and table_schema like 'mydatabase'
group by
table_name
order by
table_schema,
table_name,
ordinal_position;
2. 查询后发现存在不一样的字符集,然后修改
ALTER TABLE mydatabase.mytable DEFAULT COLLATE utf8_general_ci;
ALTER TABLE mydatabase.mytable CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
3. 把不一样字符集的表改完就没问题了
select
count( 0 )
from
information_schema.TABLES
where
table_schema =(
select
database()
)
and table_name not like 'qrtz_%'
and table_name not like 'gen_%'
and table_name not in(
select
table_name
from
gen_table
);