MySQL 如果线程丢失,则解锁表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9783636/
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
Unlocking tables if thread is lost
提问by shantanuo
http://dev.mysql.com/doc/refman/5.0/en/internal-locking.html
http://dev.mysql.com/doc/refman/5.0/en/internal-locking.html
The following is the extract from the documentation.
以下是文档的摘录。
mysql> LOCK TABLES real_table WRITE, temp_table WRITE;
mysql> INSERT INTO real_table SELECT * FROM temp_table;
mysql> DELETE FROM temp_table;
mysql> UNLOCK TABLES;
My question is that if I use this logic in the shell script code, and if the thread is lost (not killed) before it reaches "unlock tables" statement, how will I know that some tables are locked and how do I unlock tables manually?
我的问题是,如果我在 shell 脚本代码中使用此逻辑,并且如果线程在到达“解锁表”语句之前丢失(未终止),我将如何知道某些表已被锁定以及如何手动解锁表?
采纳答案by Devart
how will I know that some tables are locked?
我怎么知道有些表被锁定了?
You can use SHOW OPEN TABLEScommand to view locked tables.
您可以使用SHOW OPEN TABLES命令查看锁定的表。
how do I unlock tables manually?
如何手动解锁表?
If you know the session ID that locked tables - 'SELECT CONNECTION_ID()', then you can run KILLcommand to terminate session and unlock tables.
如果您知道锁定表的会话 ID - 'SELECT CONNECTION_ID()',那么您可以运行KILL命令来终止会话并解锁表。
回答by Kostyantyn
Here's what i do to FORCE UNLOCK FOR some locked tables in MySQL
这是我为强制解锁 MySQL 中的一些锁定表所做的工作
1) Enter MySQL
1) 进入 MySQL
mysql -u your_user -p
2) Let's see the list of locked tables
2)让我们看看锁定表的列表
mysql> show open tables where in_use>0;
3) Let's see the list of the current processes, one of them is locking your table(s)
3)让我们看看当前进程的列表,其中之一是锁定您的表
mysql> show processlist;
4) Let's kill one of these processes
4)让我们杀死这些进程之一
mysql> kill put_process_id_here;
回答by kevnk
With Sequel Pro:
使用 Sequel Pro:
Restarting the app unlocked my tables. It resets the session connection.
重新启动应用程序解锁了我的桌子。它重置会话连接。
NOTE: I was doing this for a site on my local machine.
NOTE: I was doing this for a site on my local machine.