最近在项目中查询视图时报了一个错误“Illegal mix of collations (utf8mb4_general_ci,COERCIBLE) and (utf8mb4_unicode_ci,COERCIBLE) for operation '='”。这是因为待查询字段的COLLATE与要判断的值的COLLATE不同导致的。这就需要在查询时手工指定COLLATE。例如:
WHERE 'A' COLLATE utf8mb4_unicode_ci = 'A' COLLATE utf8mb4_unicode_ci
或者:
SELECT * FROM table ORDER BY key COLLATE utf8mb4_unicode_ci;
参考网页:
https://stackoverflow.com/questions/3029321/troubleshooting-illegal-mix-of-collations-error-in-mysql