删除表使MySQL挂起

时间:2012-06-03 15:04:37

标签: mysql locks

当我尝试删除表时,MySQL挂起。我没有任何其他公开会议。怎么解决这个?我等了10个小时,这个过程还没有结束。

3 个答案:

答案 0 :(得分:17)

Waiting for table metadata lock
drop table tableA name

SELECT l1.lat, l1.lon, l2.zipcode FROM tableA l1, tableBl2 where l1.lat = l2.latitude and l1.lon = l2.longitude limit 10

如果这是您的表格,请参阅this link

你有一个隐含的死锁。杀死其他事务以释放掉线,或者杀死掉线以释放其他交易。

您可以在sql_plus中使用KILL thread_id。


我提出了更多信息,因为我想出了另一个有趣的经历。

Metadata在给定表格上的ddl操作(dropalter ...)和选择查询之间,同样会发生死锁表。

是的,select

因此,如果你在mysql(或php,例如pdo::fetch)中循环游标,并在同一个表上运行ddl语句,你将会遇到死锁。

这种非典型场景的一个解决方案是在完全提取任何select语句后系统地释放带有commit语句的隐式锁。

答案 1 :(得分:13)

重新启动MySQL可能不是最漂亮的解决方案,但它对我有用:

sudo /etc/init.d/mysql restart
mysqladmin drop YOURDATABASE

答案 2 :(得分:0)

我正在为新手尝试更简单的答案:

1)运行:

SHOW PROCESSLIST

如果您得到类似的信息:

+----+-----------------+-----------------+--------+------------+-----------+---------------------------------+---------------------------------------------------+
| Id | User            | Host            | db     | Command    | Time      | State                           | Info                                              |
+----+-----------------+-----------------+--------+------------+-----------+---------------------------------+---------------------------------------------------+
|  4 | event_scheduler | localhost       | NULL   | Daemon     | 580410103 | Waiting on empty queue          | NULL                                              |
| 13 | root            | localhost:50627 | airbnb | Sleep      |     10344 |                                 | NULL                                              |
| 17 | root            | localhost:50877 | NULL   | Query      |      2356 | Waiting for table metadata lock | SHOW FULL COLUMNS FROM `airbnb`.`characteristics` |
| 18 | root            | localhost:50878 | airbnb | Query      |      2366 | Waiting for table metadata lock | DROP TABLE `airbnb`.`characteristics`             |
| 21 | root            | localhost:51281 | airbnb | Query      |      2305 | Waiting for table metadata lock | SHOW FULL COLUMNS FROM `airbnb`.`bed_type`        |
| 22 | root            | localhost:51282 | airbnb | Query      |      2301 | Waiting for table metadata lock | SHOW INDEXES FROM `airbnb`.`characteristics`      |
| 23 | root            | localhost:51290 | airbnb | Query      |      2270 | Waiting for table metadata lock | SHOW FULL COLUMNS FROM `airbnb`.`property_type`   |
| 24 | root            | localhost:51296 | airbnb | Query      |      2240 | Waiting for table metadata lock | SHOW INDEXES FROM `airbnb`.`property_type`        |
| 26 | root            | localhost:51303 | NULL   | Query      |      2212 | Waiting for table metadata lock | SHOW FULL COLUMNS FROM `airbnb`.`characteristics` |
| 27 | root            | localhost:51304 | NULL   | Query      |      2218 | Waiting for table metadata lock | SHOW FULL COLUMNS FROM `airbnb`.`bed_type`        |
| 29 | root            | localhost:51306 | NULL   | Query      |      2176 | Waiting for table metadata lock | SHOW INDEXES FROM `airbnb`.`characteristics`      |
| 30 | root            | localhost:51308 | NULL   | Query      |      2122 | Waiting for table metadata lock | DROP TABLE `airbnb`.`characteristics`             |
| 34 | root            | localhost:51312 | NULL   | Query      |      2063 | Waiting for table metadata lock | SHOW FULL COLUMNS FROM `airbnb`.`characteristics` |
| 35 | root            | localhost:51313 | NULL   | Query      |      2066 | Waiting for table metadata lock | SHOW FULL COLUMNS FROM `airbnb`.`bed_type`        |
| 39 | root            | localhost:51338 | NULL   | Query      |      2004 | Waiting for table metadata lock | SHOW FULL COLUMNS FROM `airbnb`.`characteristics` |
| 40 | root            | localhost:51339 | NULL   | Query      |      2008 | Waiting for table metadata lock | SHOW FULL COLUMNS FROM `airbnb`.`bed_type`        |
| 45 | root            | localhost       | airbnb | Field List |       997 | Waiting for table metadata lock |                                                   |
| 46 | root            | localhost       | airbnb | Field List |       798 | Waiting for table metadata lock |                                                   |
| 53 | root            | localhost       | airbnb | Query      |         0 | starting                        | SHOW PROCESSLIST                                  |
+----+-----------------+-----------------+--------+------------+-----------+---------------------------------+---------------------------------------------------+

with State:等待表元数据锁定(如官方答案中所述)

2)KILL 13(对应ID的13个核心)。

如果这确实是一个僵局,则以下所有过程将继续正常进行。