这个问题出现再 mysql和c  的api。

简单的解决方法是不使用api直接把整个连接和命令传过去。

例如,cmd = 'mysql -h 192.168.32.210 -P 3316 -u bfdroot -pqianfendian -D DMP_GDMP_Cbehe      -e "%s"' % update_sql2

问题原因:

Mysql文档: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.

第一种 存储结果未释放,然后又查询

第二种两次查询之间没有存储结果

解决方案:

do 



    result = mysql_store_result( mysql ); 

    mysql_free_result(result); 

}while( !mysql_next_result( mysql ) );

例子 http://www.linuxidc.com/Linux/2013-04/82619.htm

: Update OK!sql: insert into  t_alarm_record_file  (recordPath,recordName,hostIp,startTime,endTime,deviceId,programNumber,deviceType,interfaceNo,alarmType,alarmTime) values ('/figure/data/AlarmRecord/StreamTS/1-码流_魅力音 乐主路/2011-11-07/20111107150116.ts','','10.0.60.2','2011-11-07
15:01:16','1970-01-01 08:00:00',37486602,3905,'0',1,12,'2011-11-07 15:01:20');update  t_alarm  set fileId = LAST_INSERT_ID()  where deviceId = 37486602 and programNumber = 3905 and alarmType = 12 and alarmDate = '2011-11-07 15:01:20' and fileId is null

2011-11-07 15:01:35,331: ERROR  : Update failed!sql: insert into  t_alarm_record_file  (recordPath,recordName,hostIp,startTime,endTime,deviceId,programNumber,deviceType,interfaceNo,alarmType,alarmTime) values ('/figure/data/AlarmRecord/StreamTS/1-码流_魅力音 乐主路/2011-11-07/20111107150116.ts','','10.0.60.2','2011-11-07
15:01:16','1970-01-01 08:00:00',37486602,3905,'0',1,13,'2011-11-07 15:01:27');update  t_alarm  set fileId = LAST_INSERT_ID()  where deviceId = 37486602 and programNumber = 3905 and alarmType = 13 and alarmDate = '2011-11-07 15:01:27' and fileId is null, ERROR:Commands
out of sync; you can't run this command now

在第一次调用Update()执行多条sql语句时成功,但以后的所有调用都失败了。

 

经过查找,发现问题在于:在Update()中执行多条sql语句时,

如果仅仅是插入等不需要返回值的SQL语句,也一样得读完整个resault集并释放,最小化的写法:

 

do 



    result = mysql_store_result( mysql ); 

    mysql_free_result(result); 

}while( !mysql_next_result( mysql ) );

 

经过这么一处理,问题终于解决了。


python mysql 2014 Commands out of sync; you can't run this command now的更多相关文章

  1. error:2014 Commands out of sync; you can't run this command now

    如下错误: 分析原因: 前端ajax请求后台,共用同一个链接. 搜索别人的解决方案:http://blog.csdn.net/grass_ring/article/details/3499402 用m ...

  2. _mysql_exceptions.ProgrammingError:(2014, "commands out of sync; you can't run this command now")

    今天,测试dashboard上的一些graph, 发现,当多个graph同时向后台请求数据(异步)的时候, 出现了上述错误.而且,三个bug交替出现,另外两个bug分别是:python stop re ...

  3. 使用otl,报错:mysql Commands out of sync; you can't run this command now

    1.代码如下: void TestCache(otl_connect& otlConn) { try { ] = {}; sprintf(sql,"call test1(1)&quo ...

  4. C mysql (C API Commands out of sync; you can't run this command now)

    错误出现在当一个用户使用查询,另一个用户再使用此sql连接进行查询的时候: 原因是因为上一次使用此sql连接进行查询时没有将所有的结果集给释放掉,在所有使用此sql连接进行查询的地方将所有的结果集给释 ...

  5. mysql_query error:Commands out of sync;you can't run this command now

    MYSQL_REST *result没有释放, 用mysql_free_result(result)即可.

  6. MySql: ”Commands out of sync“Error (Connect/C++)

    使用 Connector/C++ 查询 Mysql , 连续调用存储过程时 会出现如下: Commands out of sync; you can't run this command now,st ...

  7. ubuntu14.04下搭建python+mysql环境

    简略记录ubuntu14.04下搭建python操作的mysql服务器的过程和其中遇到的问题及解决方法. 第一部分: 安装mysql 安装步骤:1. sudo apt-get install mysq ...

  8. Python—>Mysql—>Dbvisualizer

    MySQLdb: https://pypi.python.org/pypi/MySQL-python/1.2.4 import MySQLdb 1.Download Connector/Python: ...

  9. Python Mysql 篇

    Python 操作 Mysql 模块的安装 linux: yum install MySQL-python window: http://files.cnblogs.com/files/wupeiqi ...

随机推荐

  1. div+css网页本地上和上传到服务器后在IE11上看到的效果不一样?

    div+css网页本地上和上传到服务器后在IE11上看到的效果不一样? 解决办法在html的head里加上一段:<meta http-equiv="X-UA-Compatible&qu ...

  2. 内联函数 inline 漫谈

    内联函数存在的结论是: 引入内联函数是为了解决函数调用效率的问题 由于函数之间的调用,会从一个内存地址调到另外一个内存地址,当函数调用完毕之后还会返回原来函数执行的地址.函数调用会有一定的时间开销,引 ...

  3. HDU-1232--畅通工程(最小生成树)

    Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府"畅通工程"的目标是使全省任何两个城镇间都可以实现交通 ...

  4. java 设计模式之单利模式以及代理模式(静态)

    1:单利模式: public class Singleton { private static Singleton uniqueInstance = null; private Singleton() ...

  5. Listview源码分析(1)

    首先Listview继承关系: ListView  --extends-->  AbsListview  --extends-->  AdapterView  --extends--> ...

  6. PHP中将ip地址转成十进制数的两种实用方法

    As we all know that long2ip works as ip1.ip2.ip3.ip4 (123.131.231.212) long ip => (ip1 * 256 * 25 ...

  7. HTTP 中 POST和GET的区别

    1.传送数据的方式不一样 get是将数据队列添加到URL中提交,用户可以看到(对URL反编码就行) post是将数据队列放到HTTP的报文的报头中提交,用户看不到所提交的数据: 2.服务器端获取变量的 ...

  8. 极光推送集成——iOS10 接受消息问题及解决

    iOS10升级后极光推送发生了很大的变化,要求Xcode更新到8.0及以上版本才可以实现iOS10接受消息的方法 常见错误 这个问题困扰了我一天,辛亏好友盼神帮我解决,在此再次感谢盼神.一下是解决办法 ...

  9. Combox下拉绑定DataGridView

    这个Combox下拉很多人都在用  但其中绘制的语句如下: #endregion #region 方法 #region 绘制DataGridView以及下拉DataGridView private v ...

  10. 关于js的几道经典题(作用域、原型链等)自己做的

    1. function test() { var a = 1; setTimeout(function() { alert(a); a = 3; }, 1000); a = 2; setTimeout ...