记录mysql使用SET报字符集异常 1267 - Illegal mix of collations

122 阅读1分钟

语句

SET @orderCode = "xxx";
SELECT  * from order where code = @orderCode;

异常: Illegal mix of collations (utf8mb4_general_ci,COERCIBLE) and (latin1_swedish_ci,NUMERIC)

执行

SHOW VARIABLES LIKE 'coll%';

sql结果 image.png

将之前的sql改为

SET collation_connection = 'utf8mb4_general_ci';
SET @orderCode = "xxx";
SELECT  * from order where code = @orderCode;

或者修改全局的collation_connection