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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- create table if not exists Waiting for table metadata lockAI
- MySQL新增索引偶遇waiting for table metadata lockMySql索引AI
- MySQL DDL Waiting for table metadata lock 解決MySqlAI
- MySQL 5.6 drop database時,table metadata lock等待MySqlDatabase
- 【Mysql】metadata lock鎖MySql
- MYSQL 鎖:metadata lockMySql
- 【MySQL】MetaData Lock 之一MySql
- 【MySQL】MetaData Lock 之二MySql
- 【MySQL】MetaData Lock 之三MySql
- MySQL:Analyze table導致'waiting for table flush'MySqlAI
- mysql觀測METADATA LOCK(MDL)鎖MySql
- mysql metadata lock原理與實現MySql
- MySQL5.7 Waiting FOR TABLE FLUSHMySqlAI
- MySQL 5.6 metadata lock 原始碼解讀MySql原始碼
- MySQL5.7 Waiting for global read lockMySqlAI
- 【MySQL】select for update 的Row Lock 與Table LockMySql
- Waiting for table阻塞查詢的問題AI
- enable table lock 的enqueue等待ENQ
- ORA-04021: timeout occurred while waiting to lock objectWhileAIObject
- Another app is currently holding the yum lock; waiting for it to exit...APPAI
- ORA-04021,timeout occurred while waiting to lock objectWhileAIObject
- Get detailed table(many other objects) structure with dbms_metadataAIObjectStruct
- mysql metadata lock後設資料鎖之鎖狀態lock_status流轉圖MySql
- MYSQL METADATA LOCK(MDL LOCK)學習(1) 理論知識和加鎖型別測試MySql型別
- Oracle blocking issue with lock table in exclusive modeOracleBloC
- MySQL:簡單記錄一下Waiting for commit lockMySqlAIMIT
- ORA-02049: timeout: distributed transaction waiting for lockAI
- yum 提示 Another App is currently holding the yum lock; waiting for it to exit...APPAI
- 【Mysql】從庫大量select堵塞,Waiting for table flush 狀態MySqlAI
- MySQL表結構變更引起的Metadata Lock|如何定位DDL被阻塞MySql
- v$lock之alter table drop column與alter table set unused column區別系列五
- 當匯入flutter專案時,報Waiting for another flutter command to release the startup lockFlutterAI
- Another app is currently holding the yum lock; waiting for it to exit...另一個應用程式在佔用yum lock,等待其退出。APPAI
- 解決rpmdb: Lock table is out of available locker entries問題。AI
- ERROR 1206 (HY000): The total number of locks exceeds the lock table sizeError
- dbms_stats.lock_table_stats與動態取樣(Dynamic Sampling)
- 解析arxiv Metadata
- ASM Metadata and InternalsASM