php innodb_lock_wait_timeout 增加超时时间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28735473/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:01:52  来源:igfitidea点击:

innodb_lock_wait_timeout increase timeout

phpmysqldatabasetimeoutinnodb

提问by user3819192

I am using MySQL database and trying to update records just after insert so I am getting following error ER_LOCK_WAIT_TIMEOUT: Lock wait timeout exceeded; try restarting transaction. So I decrease timeout by following query:-

我正在使用 MySQL 数据库并尝试在插入后更新记录,因此出现以下错误ER_LOCK_WAIT_TIMEOUT: Lock wait timeout exceeded; try restarting transaction。所以我通过以下查询减少超时:-

set GLOBAL innodb_lock_wait_timeout=1

So my question is:- is it ok to do that? Will it lead to other problems like performance issue etc.?

所以我的问题是:-可以这样做吗?它会导致性能问题等其他问题吗?

Thank You for your help.

感谢您的帮助。

回答by Rick James

If this is a web application and you are trying to hang onto the transaction from one page to the next, don't; it won't work.

如果这是一个 Web 应用程序并且您试图从一个页面到下一个页面挂起事务,请不要;它不会工作。

What do you mean by "just after"? If you are doing nothing between the two statements, even a timeout of 1 second should be big enough.

你说的“就在之后”是什么意思?如果你在两个语句之间什么都不做,即使是 1 秒的超时也应该足够大。

mysql> SET GLOBAL innodb_lock_wait_timeout = 1;
mysql> SELECT @@innodb_lock_wait_timeout;
+----------------------------+
| @@innodb_lock_wait_timeout |
+----------------------------+
|                         50 |
+----------------------------+
mysql> SET SESSION innodb_lock_wait_timeout = 1;
mysql> SELECT @@innodb_lock_wait_timeout;
+----------------------------+
| @@innodb_lock_wait_timeout |
+----------------------------+
|                          1 |
+----------------------------+

To explain GLOBAL vs SESSION for VARIABLES: The GLOBAL value is used to initializethe SESSION value when your connection starts. After that, you can change the SESSION value to affect what you are doing. And changing the GLOBAL value has no effect on your currentconnection.

解释变量的 GLOBAL 与 SESSION: GLOBAL 值用于在连接开始时初始化SESSION 值。之后,您可以更改 SESSION 值以影响您正在执行的操作。更改 GLOBAL 值对您当前的连接没有影响。

Changing the timeout to 1 is quite safe (once you understand GLOBAL vs SESSION). The only thing that will change is the frequency of getting that error.

将超时更改为 1 是非常安全的(一旦您了解了 GLOBAL vs SESSION)。唯一会改变的是出现错误的频率。