MySQL 错误 #2014 - 命令不同步;你现在不能运行这个命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8891179/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MySQL error #2014 - Commands out of sync; you can't run this command now
提问by kid Nguyen
I am using MySQL and I am defining a stored procedure like this:
我正在使用 MySQL,我正在定义一个这样的存储过程:
delimiter ;;
Create procedure sp_test()
select * from name_table;
end
When I try to execute that procedure I get this error:
当我尝试执行该过程时,出现此错误:
#2014 - Commands out of sync; you can't run this command now
What does this mean and what am I doing wrong?
这是什么意思,我做错了什么?
回答by Marco
From Manual
从手册
C.5.2.14. Commands out of sync
If you getCommands 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.
C.5.2.14。命令不同步
如果您进入Commands out of sync; you can't run this command now
您的客户端代码,您正在以错误的顺序调用客户端函数。例如,如果您
mysql_use_result()
在调用 之前使用并尝试执行新查询,就会发生这种情况mysql_free_result()
。如果您尝试执行两个返回数据而不调用mysql_use_result()
或mysql_store_result()
介于两者之间的查询,也会发生这种情况。
This post (taken from here)
这篇文章(取自这里)
I've solved that problem. I use MySQL-Fron instead MySQL Query browser. And everything works fine.
我已经解决了那个问题。我使用 MySQL-Fron 代替 MySQL 查询浏览器。一切正常。
makes me think that it's not a server or database problem but a problem in the tool you're using.
让我认为这不是服务器或数据库问题,而是您使用的工具中的问题。
回答by Eric Leschinski
I was able to reproduce this error with MySQL and phpmyadmin:
我能够使用 MySQL 和 phpmyadmin 重现此错误:
#2014 - Commands out of sync; you can't run this command now
On this version of MySQL:
在这个版本的 MySQL 上:
el@apollo:~$ mysql --version
mysql Ver 14.14 Distrib 5.5.34, for debian-linux-gnu (x86_64) using readline 6.2
With the following SQL run through the phpmyadmin query window:
使用以下 SQL 通过 phpmyadmin 查询窗口运行:
use my_database;
DELIMITER $$
CREATE PROCEDURE foo()
BEGIN
select 'derp' as 'msg';
END $$
CALL foo()$$ <----Error happens here, with or without delimiters.
I couldn't get the error to happen through the MySQL terminal, so I think it's a bug with phpmyadmin.
我无法通过 MySQL 终端发生错误,所以我认为这是 phpmyadmin 的错误。
It works fine on the terminal:
它在终端上工作正常:
mysql> delimiter $$
mysql> use my_database$$ create procedure foo() begin select 'derp' as 'msg'; end $$ call foo() $$
Database changed
Query OK, 0 rows affected (0.00 sec)
+------+
| msg |
+------+
| derp |
+------+
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
I think the bug has something to do with changing the delimiters mid-query within phpmyadmin.
我认为该错误与更改 phpmyadmin 中的分隔符中间查询有关。
Workaround:Slow down there, cowboy, and run your SQL statements one at a time when using phpmyadmin. phpmyadmin is "single task bob", he can only do one job.
解决方法:放慢速度,牛仔,在使用 phpmyadmin 时一次运行一个 SQL 语句。phpmyadmin 是“单任务鲍勃”,他只能做一份工作。
回答by michael
The possible reason is that mysql client in your code is not thread safe, i encountered the same error when I call mysqldb in python, I have one mysql interface, used in 2 threads, the error happens. In this situation, you need to create more mysql interfaces along with threads.
可能的原因是你代码中的mysql客户端不是线程安全的,我在python中调用mysqldb时遇到了同样的错误,我有一个mysql接口,在2个线程中使用,错误发生了。在这种情况下,您需要创建更多的 mysql 接口以及线程。
回答by William Desportes
I fixed this issue on phpMyAdmin 4.8.6
我在 phpMyAdmin 4.8.6 上解决了这个问题
Issue: https://github.com/phpmyadmin/phpmyadmin/issues/14614
问题:https: //github.com/phpmyadmin/phpmyadmin/issues/14614
Pull-Request: https://github.com/phpmyadmin/phpmyadmin/pull/15234
拉取请求:https: //github.com/phpmyadmin/phpmyadmin/pull/15234
The patch: https://github.com/phpmyadmin/phpmyadmin/pull/15234/files#diff-de1b7e9dd5969db226563678c658ea67
补丁:https: //github.com/phpmyadmin/phpmyadmin/pull/15234/files#diff-de1b7e9dd5969db226563678c658ea67
The patch consists into and if mysqli_more_resultsthen a call to mysqli_next_result
该补丁包含如果mysqli_more_results然后调用mysqli_next_result
回答by redmoon7777
You forgot to use the 'Begin' keyword, and during compilation MySQL is confused, this should work:
您忘记使用 'Begin' 关键字,并且在编译期间 MySQL 很困惑,这应该可以工作:
DELIMITER ;;
Create procedure sp_test()
BEGIN
select * from name_table;
END;;
DELIMITER ;
回答by chemicaluser
Suppose that when you created the stored procedure you stored it in database named mydatabase
to CALL the procedure. Go to your localhost DB and:
假设当您创建存储过程时,您将其存储在名为mydatabase
CALL 过程的数据库中。转到您的本地主机数据库并:
CALL mydatabase.sp_test();
Where sp_test()
is the name of your procedure.
sp_test()
您的程序名称在哪里。
回答by ALM
I also encountered this problem with a C API.
我在 C API 中也遇到了这个问题。
I found the solution with the last example above, which speaks of delimiters.
我在上面的最后一个例子中找到了解决方案,它谈到了分隔符。
use my_database;
DELIMITER $$
CREATE PROCEDURE foo()
BEGIN
select 'derp' as 'msg';
END $$
CALL foo()$$
My code executes a stored procedure then tests the return. I use correctly the mysql_free_result().
我的代码执行一个存储过程然后测试返回。我正确使用了 mysql_free_result()。
Since I have not added a select clause "into" in the procedure, this error occurred.
由于我没有在程序中添加 select 子句“into”,所以发生了这个错误。
The last example above is in the same case.
上面的最后一个例子是同样的情况。
I have deleted the select and since it's ok.
我已经删除了选择,因为没关系。
Alex
亚历克斯
回答by tlum
I just got the same error from phpMYadmin when calling a user function I'm working on.
在调用我正在处理的用户函数时,我刚刚从 phpMYadmin 收到了同样的错误。
mysql console says however:
然而 mysql 控制台说:
ERROR 1054 (42S22): Unknown column 'latitude' in 'field list'
...which is absolutely correct, it was misspelled in the field list, so a statement was referencing an undefined variable.
...这是绝对正确的,它在字段列表中拼写错误,因此语句引用了未定义的变量。
I'd have to conclude that
我必须得出结论
#2014 - Commands out of sync; you can't run this command now
from phpMYadmin is a rather non-specific error, than in many cases, if not most, is just obscuring the real problem, and one should not spend too much time trying to make sense out of it.
来自 phpMYadmin 是一个相当非特定的错误,而不是在许多情况下,如果不是大多数,只是掩盖了真正的问题,人们不应该花太多时间试图理解它。
回答by Ayaskant Mishra
回答by ethis
This was happening to me because a function within an procedure gave a value back that wasn't allocated to a variable.
这发生在我身上,因为过程中的一个函数返回了一个未分配给变量的值。
The solution was:
解决方案是:
select function .... INTO @XX;