Cannot convert string ‘\xE9\x87...‘ from utf8mb4 to binary

在MySQL8.0.32中,使用UNION操作结合LIKE进行模糊查询时出现错误,日志显示字符集转换警告。官方文档指出这是由于条件推下到UNION查询时字符集处理不一致导致。临时解决方案是关闭optimizer_switch中的derived_condition_pushdown选项,可以通过设置会话、全局变量或配置文件实现。重启数据库后问题可得到解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

版本环境

  • MySQL 8.0.32

问题

使用union连接表后,通过关键字like模糊查询内容时报错。

查看日志show warnnings显示如下:

|level   | code | message                                                    |
|Warning | 1300 | Cannot convert string '\xE9\x87...' from utf8mb4 to binary |

官方解释文档

A condition pushdown into a UNION of queries having LIKE clauses did not preserve the correct character set, leading to an (erroneous) empty result.
We solve this problem in two parts:
By refactoring resolution of LIKE expressions, in which character set determination and propagation were previously performed in two separate blocks of the code that were not always consistent with one another.
By adding, in the internal parse_expression() function, a character set prefix to any literal character string that is cloned.
(Bug #107787, Bug #34359297, Bug #34589153)

Bug #107787 链接

临时解决办法

修改optimizer_switchderived_condition_pushdown值为off

# 设置当前会话
set optimizer_switch='derived_condition_pushdown=off';
# 设置全局值
set global optimizer_switch='derived_condition_pushdown=off';
# 设置全局值,并固化到配置⽂件my.cnf
set persist optimizer_switch='derived_condition_pushdown=off';

重启数据库systemctl restart mysqld,解决~~

原文:https://greatsql.cn/thread-209-1-1.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值