Waiting for table metadata lock
一個沒提交的事務使用了A表, 另外一個session 對A表進行alter,出現waiting for table metadata lock
解決方法:檢視information_schema.INNODB_TRX擁有事務的trx_mysql_thread_id,kill trx_mysql_thread_id回滾事務
如:
SessionA
mysql> select * from t1;
+---+------+------+------+------+
| x | y | z | a | b |
+---+------+------+------+------+
| 1 | 1 | NULL | NULL | NULL |
| 2 | 2 | NULL | NULL | NULL |
| 3 | 3 | NULL | NULL | NULL |
+---+------+------+------+------+
3 rows in set (0.00 sec)
mysql> begin;
mysql> update t1 set x=y+3;
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> select * from t1;
+---+------+------+------+------+
| x | y | z | a | b |
+---+------+------+------+------+
| 4 | 1 | NULL | NULL | NULL |
| 5 | 2 | NULL | NULL | NULL |
| 6 | 3 | NULL | NULL | NULL |
+---+------+------+------+------+
3 rows in set (0.02 sec)
session B:
mysql> alter table t1 drop b;
等待
mysql> select trx_id,trx_state,trx_started,trx_requested_lock_id,trx_wait_started,trx_weight,trx_mysql_thread_id,trx_query,trx_operation_state from information_schema.INNODB_TRX\G
*************************** 1. row ***************************
trx_id: 12101
trx_state: RUNNING
trx_started: 2014-11-19 11:18:33
trx_requested_lock_id: NULL
trx_wait_started: NULL
trx_weight: 9
trx_mysql_thread_id: 6
trx_query: NULL
trx_operation_state: NULL
1 row in set (0.00 sec)
mysql> show full processlist;
+----+------+-----------+--------------------+---------+------+---------------------------------+-----------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+--------------------+---------+------+---------------------------------+-----------------------+
| 3 | root | localhost | test | Query | 76 | Waiting for table metadata lock | alter table t1 drop b |
| 4 | root | localhost | information_schema | Query | 0 | init | show full processlist |
| 6 | root | localhost | test | Sleep | 64 | | NULL |
+----+------+-----------+--------------------+---------+------+---------------------------------+-----------------------+
3 rows in set (0.00 sec)
mysql> kill 6;
Query OK, 0 rows affected (0.00 sec)
session B:
執行成功
mysql> alter table t1 drop b;
Query OK, 0 rows affected (1 min 52.33 sec)
Records: 0 Duplicates: 0 Warnings: 0
Session A:
之前的操作被回滾
mysql> select * from t1;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 7
Current database: test
+---+------+------+------+
| x | y | z | a |
+---+------+------+------+
| 1 | 1 | NULL | NULL |
| 2 | 2 | NULL | NULL |
| 3 | 3 | NULL | NULL |
+---+------+------+------+
3 rows in set (0.00 sec)
解決方法:檢視information_schema.INNODB_TRX擁有事務的trx_mysql_thread_id,kill trx_mysql_thread_id回滾事務
如:
SessionA
mysql> select * from t1;
+---+------+------+------+------+
| x | y | z | a | b |
+---+------+------+------+------+
| 1 | 1 | NULL | NULL | NULL |
| 2 | 2 | NULL | NULL | NULL |
| 3 | 3 | NULL | NULL | NULL |
+---+------+------+------+------+
3 rows in set (0.00 sec)
mysql> begin;
mysql> update t1 set x=y+3;
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> select * from t1;
+---+------+------+------+------+
| x | y | z | a | b |
+---+------+------+------+------+
| 4 | 1 | NULL | NULL | NULL |
| 5 | 2 | NULL | NULL | NULL |
| 6 | 3 | NULL | NULL | NULL |
+---+------+------+------+------+
3 rows in set (0.02 sec)
session B:
mysql> alter table t1 drop b;
等待
mysql> select trx_id,trx_state,trx_started,trx_requested_lock_id,trx_wait_started,trx_weight,trx_mysql_thread_id,trx_query,trx_operation_state from information_schema.INNODB_TRX\G
*************************** 1. row ***************************
trx_id: 12101
trx_state: RUNNING
trx_started: 2014-11-19 11:18:33
trx_requested_lock_id: NULL
trx_wait_started: NULL
trx_weight: 9
trx_mysql_thread_id: 6
trx_query: NULL
trx_operation_state: NULL
1 row in set (0.00 sec)
mysql> show full processlist;
+----+------+-----------+--------------------+---------+------+---------------------------------+-----------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+--------------------+---------+------+---------------------------------+-----------------------+
| 3 | root | localhost | test | Query | 76 | Waiting for table metadata lock | alter table t1 drop b |
| 4 | root | localhost | information_schema | Query | 0 | init | show full processlist |
| 6 | root | localhost | test | Sleep | 64 | | NULL |
+----+------+-----------+--------------------+---------+------+---------------------------------+-----------------------+
3 rows in set (0.00 sec)
mysql> kill 6;
Query OK, 0 rows affected (0.00 sec)
session B:
執行成功
mysql> alter table t1 drop b;
Query OK, 0 rows affected (1 min 52.33 sec)
Records: 0 Duplicates: 0 Warnings: 0
Session A:
之前的操作被回滾
mysql> select * from t1;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 7
Current database: test
+---+------+------+------+
| x | y | z | a |
+---+------+------+------+
| 1 | 1 | NULL | NULL |
| 2 | 2 | NULL | NULL |
| 3 | 3 | NULL | NULL |
+---+------+------+------+
3 rows in set (0.00 sec)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/27000195/viewspace-1356860/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL新增索引偶遇waiting for table metadata lockMySql索引AI
- MySQL DDL Waiting for table metadata lock 解決MySqlAI
- MySQL:Analyze table導致'waiting for table flush'MySqlAI
- MySQL5.7 Waiting for global read lockMySqlAI
- MySQL5.7 Waiting FOR TABLE FLUSHMySqlAI
- mysql觀測METADATA LOCK(MDL)鎖MySql
- ORA-04021: timeout occurred while waiting to lock objectWhileAIObject
- yum 提示 Another App is currently holding the yum lock; waiting for it to exit...APPAI
- MySQL:簡單記錄一下Waiting for commit lockMySqlAIMIT
- [20190522]DISABLE TABLE LOCK.txt
- mysql metadata lock後設資料鎖之鎖狀態lock_status流轉圖MySql
- [20190524]DISABLE TABLE LOCK(12c).txt
- [20190530]DISABLE TABLE LOCK(10g).txt
- GaussDB資料庫SQL系列-LOCK TABLE資料庫SQL
- 當匯入flutter專案時,報Waiting for another flutter command to release the startup lockFlutterAI
- MySQL表結構變更引起的Metadata Lock|如何定位DDL被阻塞MySql
- Qt MetadataQT
- 2.3.2.2.1 Metadata Links
- 解析arxiv Metadata
- 8.11.4 Metadata Locking
- Waiting for target device to come onlineAIdev
- ## yum提示Another app is currently holding the yum lock; waiting for it to exit... 這是因為有另一個yum程式正在執行APPAI
- @EnableAsync annotation metadata was not injected
- ASM Metadata Dump UtilityASM
- 2.1.3.2 Metadata and Data Links
- Full GC (Metadata GC Threshold)GC
- Guideline 2.3.10 - Performance - Accurate MetadataGUIIDEORM
- Swift 5 Type Metadata 詳解Swift
- Lock 鎖
- create table,show tables,describe table,DROP TABLE,ALTER TABLE ,怎麼使用?
- MySQL Cases-記錄大量waiting for handler commitMySqlAIMIT
- mysql innodb lock鎖之record lock之一MySql
- 2.3.2.2 Metadata-Linked Application Common ObjectsAPPObject
- MySQL8.0 binlog_row_metadataMySql
- 解決:Failed to download metadata for repo ‘base‘AI
- Error waiting for a debug connection: ProcessException: adb did not report forwarded portErrorAIExceptionForward
- Oracle例項關閉:SHUTDOWN: waiting for active calls to completeOracleAI
- PAT甲級-1014. Waiting in Line (30)(模擬)AI
- Failed to connect to ESP8266: Timed out waiting for packet headerAIHeader