python mysql 2014 Commands out of sync; you can't run this command now
2013-10-16 17:24
501 查看
这个问题出现再 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 ) );
经过这么一处理,问题终于解决了。
简单的解决方法是不使用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 ) );
经过这么一处理,问题终于解决了。
相关文章推荐
- _mysql_exceptions.ProgrammingError:(2014, "commands out of sync; you can't run this command now")
- python mysql 2014 Commands out of sync; you can't run this command now
- 解决error:2014 Commands out of sync; you can't run this command now
- 解决error:2014 Commands out of sync; you can't run this command now
- C++ Mysql调用 错误:2014 :Commands out of sync; you can't run this command now
- mysql 2014 error (2014) Commands out of sync; You can't run this command now命令不同步错误解决
- error:2014 Commands out of sync; you can't run this command now
- mysql_query error:Commands out of sync;you can't run this command now
- 使用otl,报错:mysql Commands out of sync; you can't run this command now
- MySQL问题一则:Commands out of sync; you can't run this command now以及相关问题
- C mysql (C API Commands out of sync; you can't run this command now)
- PHP执行MYSQL存储过程报错:Commands out of sync; you can't run this command now
- 解决mysql error:2014 Commands out of sync; you can't run this command now
- PHP执行MYSQL存储过程报错:Commands out of sync; you can't run this command now
- MySQL一次执行多条语句的实现及常见问题(C API Commands out of sync; you can't run this command now)
- 解决error:2014 Commands out of sync; you can't run this command now
- PHP+MySQL连续插入数据报错:Commands out of sync; you can't run this command now & 读取Excel数据并批量插入到数据中
- Mysql::Error: Commands out of sync; you can't run this command now: SHOW TABLES解决方案
- mysql 出现 Commands out of sync; you can't run this command now
- php用mysql_query()调用存储过程后无法再执行sql报错:commands out of sync you can't run this command now