mysql error:2014 Commands out of sync; you can't run this command now
最近在项目中经常会出现数据库操作失败的,日志抛出的错误的 Commands out of sync; you can't run this command now。但是把具体的这条sql语句放到可视化工具里面执行却并没有什么问题。所以sql语句并没有什么语法的问题,mysql官方对这个错误的解释是:
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 calledmysql_free_result()
. It can also happen if you try to execute two queries that return data without callingmysql_use_result()
ormysql_store_result()
in between.
大概的意思就是说你在使用 mysql_use_result()
之前并没有调用mysql_free_result(),或者是你尝试执行两次查询,但是在两次查询的中间你并没有对返回数据调用
mysql_use_result()
ormysql_store_result()就行处理。
排查了所有的带结果集的sql操作,也都进行了mysql_free_result。多次定位发现,程序是调用了一个多条update语句拼接的一个sql命令。 这条update语句是执行成功了,但是却导致了后续的所有mysql错误都是抛出Commands out of sync; you can't run this command now
的错误。
在mysql在connect函数中可以指定
CLIENT_MULTI_STATEMENTS 选项来一次执行通过分号分割的多条sql语句。通过查阅资料发现对于一次执行多条update(或者insert)这类无结果集的sql操作我们也需要对其进行ysql_free_result,在sql语句执行完后加上下面的代码便解决该问题
do
{ result = mysql_store_result( mysql ); mysql_free_result(result);
}while( !mysql_next_result( mysql ) );
有点奇怪,为什么result明明获取出来是NULL,但还是要执行mysql_free_result操作。希望有明白之人可以讲解一下
mysql error:2014 Commands out of sync; you can't run this command now相关推荐
- mysql执行存储过程提示out of_PHP执行MYSQL存储过程报错:Commands out of sync; you can't run...
php中在同时执行2个存储过程时,有一个程序2个储存过程都执行,有一个程序只执行第一个调用.2个都执行的调用如下: $mydb->query("delete from pinfo wh ...
- commands out of sync mysql_MySQL问题一则:Commands out of sync; you can't run this command now以及相关问题...
录制程序有一功能:将录制的文件信息写入MySQL数据库,供BS系统查询. 因此封装了一个MySQL类,进行数据库操作. 主要接口为Update():执行SQL语句. 现在问题来了: (一)在某个场景下 ...
- MySQL Error:1677
现象: 突然接收到zabbix的警报,MySQL主从架构中的slave进程状态异常如下: 检查: 登录到服务器上面检查相关信息: 分析 如果主服务器和从服务器的列定义不同,并且使用基于ROW的二进制日 ...
- mysql error :1114 - The table ‘XXX‘ is full
背景 因为本地测试库的一张表数据不需要了,想要使用truncate进行删除.执行操作:TRUNCATE shop.user; 时提示:1114 - The table 'user' is full, ...
- MySQL ERROR:1153 的解决方法
1153 的解决方法 报错:I had the same problem, with an 8gb .sql file. I didn't have any luck with --max_allow ...
- commands out of sync mysql,MySQL-python: Commands out of sync
在给 MySQL 数据库访问层增加新功能时遇到了这样的错误: ProgrammingError: (2014, "Commands out of sync; you can't run th ...
- Mysql++关于多数据集查询Commands out of sync; you can‘t run this command now的问题
今天在项目中使用了Mysql++调用Mysql的存储过程来实现功能,但是碰到一个有意思的问题,当成功调用存储过程后,再次做其他的查询,确返回Commands out of sync; you can' ...
- commands out of sync错误
第一种情况: commands out of sync. Did you run multiple statements at once 可能的原因:是在事务之中写了查询语句. 解决方案:把查询语句 ...
- 「golang」panic: commands out of sync. Did you run multiple statements at once
[问题现象] go使用go-sql-driver连接mariaDB,如下,提示: panic: commands out of sync. Did you run multiple statement ...
最新文章
- bzoj1266: [AHOI2006]上学路线route
- 使用Spring Data Redis操作Redis(集群版)
- 【OpenCV】将RGB图像转为灰度图
- cssd拉起oracle,oracle rac /etc/init.d/init.cssd startcheck
- 纪事本 乱码_纪事地图和Yahoo Cloud服务基准
- 访问修饰符作用范围由大到小是_9个java基础小知识
- mysql安全措施_MySQL数据库在网络安全方面的一些防御措施
- 后来,我学会了每做完一件事
- php数组排序语言,php数组排序函数有哪些
- 命令行登录防止MySQL密码泄露的几个小妙招。
- Excel 取消身份证的科学计数法显示形式
- 【java】io流之字符输出流:java.io.Writer类及子类的子类java.io.FileWriter
- 《一页纸项目管理》——读书笔记
- 百度网盘提取码_百度网盘提取码查询神器分享
- 解决微信二次分享失败
- 第11章 Docker 中 Gitlab 的安装与配置
- 整个AppData目录挪到D盘方法
- 训练样本裁剪,背景裁剪,yoloV5裁剪样本检测
- windows网络排查
- Misc训练笔记(一)