mysql插入表时发生的情况达到wait_timeout限制

时间:2017-08-30 21:11:19

标签: mysql locking

我们在bash脚本中有以下MySQL任务:

INSERT INTO  blah blah blah;


ALTER TABLE table RENAME TO table_OLD;

现在MySQL INSERT查询运行超过11个小时,但仍未完成。然后ALTER表查询启动,使自己等待元数据锁定,因为INSERT查询仍在运行(根据“SHOW FULL PROCESSLIST& SHOW ENGINE INNODB STATUS”)。

当mysql插入一个达到wait_timeout限制的表时发生了什么,这是8小时。一旦达到限制,MySQL是否会在解锁插入的表时继续运行它?谢谢!

以下是一些测试:当INSERT INTO超过1秒时,INSERT INTO查询仍显示正在运行并最终完成。 “Wait_timeout”限制到底有什么作用?阅读MySQL用户手册后,我仍然很困惑。 (https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_wait_timeout)有什么想法吗?

SET SESSION wait_timeout = 1;

SHOW SESSION VARIABLES LIKE "wait_timeout"; -- 1

INSERT INTO  blah blah blah;


ALTER TABLE table RENAME TO table_OLD;

1 个答案:

答案 0 :(得分:0)

我怀疑它会断开与DB的连接,迫使你重新连接,从而切断了插件的连接

发现此网站非常有用:https://www.digitalocean.com/community/questions/how-to-set-no-timeout-to-mysql

这里只是关于从DigitalOcean删除超时的摘要

Edit your my.cnf (MySQL config file)
sudo nano /etc/mysql/my.cnf

然后

wait_timeout = 28800
interactive_timeout = 28800

The interactive timeout does not affect any web application connections. A high interactivetimeout but a low waittimeout is normal and is the best practice.

Choose a reasonable waittimeout value. Stateless PHP environments do well with a 60 second timeout or less. Stateful applications that use a connection pool (Java, .NET, etc.) will need to adjust waittimeout to match their connection pool settings. The default 8 hours (wait_timeout = 28800) works well with properly configured connection pools.