由于元数据锁定,无法重命名 table

Unable to rename table due to metadata lock

我正在尝试重命名 table,但它总是挂在 Waiting for table metadata lock 上。以下是我尝试这样做的方式:

start transaction;
RENAME TABLE `main_territorypricing` TO `main_territorypricing2`;
RENAME TABLE `main_territorypricing1` TO `main_territorypricing`;
COMMIT;

然而第一​​个重命名语句无限期挂起。我将如何重命名这两个 tables?

我很确定RENAME TABLE会终止交易。

您可以在单个原子语句(无事务)中进行两次重命名:

RENAME TABLE `main_territorypricing`  TO `main_territorypricing2`,
             `main_territorypricing1` TO `main_territorypricing`;

它将不得不等待忙于任何表的任何其他连接;确保你没有一些联系不放手。