General error: 1267 Illegal mix of collations
在使用mysql视图时,报错
1
|
SQLSTATE[HY000]: General error: 1267 Illegal mix of collations (utf8mb4_general_ci,COERCIBLE) and (utf8mb4_unicode_ci,COERCIBLE) for operation '='
|
通过命令
1
|
SHOW CREATE TABLE view_table_name;
|
查看字符集,以及排序规则
character_set_client |
collation_connection |
utf8mb4 |
utf8mb4_general_ci |
发现视图的排序规则错误。
删除原有view 并重建
1
2
3
4
5
6
|
-- 设置排序规则
SET collation_connection = utf8mb4_unicode_ci;
-- 删除原有的view
drop VIEW view_table_name;
-- 重新新建view
create view view_table_name ....
|
如果是字符集报错,同理修改即可。
1
2
3
|
SET character_set_client = utf8mb4;
SET character_set_results = utf8mb4;
SET character_set_connection = utf8mb4;
|
参考资料: https://stackoverflow.com/questions/9422189/why-is-my-view-utf8-and-how-can-i-change-it-to-latin1