ERROR (ProgrammingError) (2014, "Commands out of sync; you can't run this command now")

错误场景:

使用Python开发的数据库升级工具,在升级脚本行遇到如下语句报错了:

DROP TRIGGER IF EXISTS acl_2_ael_insert;
CREATE TRIGGER acl_2_ael_insert AFTER INSERT ON alarmclientlog
FOR EACH ROW 
UPDATE alarmeventlog SET alarm_deal_type = new.alarm_deal_type 
    WHERE alarmeventlog.strIndex = new.strIndex 
        AND alarmeventlog.strUniqueTime = new.strUniqueTime;

先解释下这段语句,alarmeventlog 表示原始报警日志,alarmclientlog 表示报警处理日志。当alarmclientlog 插入或更新后,要把处理结果也同步到alarmeventlog 里面去。
因此,我创建一个触发器做同步操作,为防止之前已经有此触发器,我先检查并删除下。


问题定位:

在网上搜到如下有用的资料:

Python’s MySQLdb 2014 Error – Commands out of sync
这里面说可能跟多条语句放在一起执行有关。

但是有些语句是可以放在一起执行的,那是不是对SQL语句的类型由要求?
然后我找到了这个帖子,是创建存储过程时发现的:
Python, “commands out of sync; you can’t run this command now”

这位也一样:
解决error:2014 Commands out of sync; you can’t run this command now

其他错误:
2014 - Commands out of sync; you can’t run this command now


解决问题:

综上所述,我感觉触发器、存储过程、SHOW等命令语句不能放一起执行。【待查】

解决方案是把语句分开执行。

在MySQL的官网手册,我发现了这个问题的说明:

B.5.2.14 Commands out of sync

If you get Commands out of sync; you can’t run this command now in
your client code, you are calling client functions in the wrong order.

This can happen, for example, if you are using mysql_use_result() and
try to execute a new query before you have called mysql_free_result().
It can also happen if you try to execute two queries that return
data without calling mysql_use_result() or mysql_store_result() in
between.

网址:B.5.2.14 Commands out of sync

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值