我运行以下查询,它是我的大型(2个vCPU,7.5 GB RAM,100GB SSD)RDS托管数据库上运行的唯一查询。
DELETE
FROM books
WHERE book_type = '/type/edition'
AND json LIKE '%"languages":%'
AND json NOT LIKE '%/eng%';
但我收到以下错误。
Error Code: 1205. Lock wait timeout exceeded; try restarting transaction
我使用SET innodb_lock_wait_timeout = 1200;
将超时时间增加到1200秒。
然而,我得到同样的错误。数据库上没有运行其他查询,它是新创建的,而不是生产中。以下是show processlist
:
+---+----------+----------------------------------------------------------+-------------+-------+-----+----------+------------------------------------------------------------------------------------------------------+
| 1 | rdsadmin | localhost:37959 | | Sleep | 10 | | |
+---+----------+----------------------------------------------------------+-------------+-------+-----+----------+------------------------------------------------------------------------------------------------------+
| 5 | website | host109-156-119-150.range109-156.btcentralplus.com:57923 | openlibrary | Sleep | 606 | | |
| 6 | website | host109-156-119-150.range109-156.btcentralplus.com:57924 | openlibrary | Query | 599 | updating | DELETE FROM books WHERE book_type = '/type/edition' AND json LIKE '%"languages":%' AND json NOT LIKE |
| 8 | website | host109-156-119-150.range109-156.btcentralplus.com:58021 | openlibrary | Sleep | 145 | | |
| 9 | website | host109-156-119-150.range109-156.btcentralplus.com:58022 | openlibrary | Query | 0 | init | show processlist |
+---+----------+----------------------------------------------------------+-------------+-------+-----+----------+------------------------------------------------------------------------------------------------------+
以下是此表的架构。
CREATE TABLE `books` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`book_type` varchar(50) DEFAULT NULL,
`book_key` varchar(50) DEFAULT NULL,
`revision` tinyint(4) DEFAULT NULL,
`last_modified` varchar(50) DEFAULT NULL,
`json` text,
`date` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `book_type` (`book_type`),
KEY `book_key` (`book_key`),
KEY `revision` (`revision`)
) ENGINE=InnoDB AUTO_INCREMENT=97545025 DEFAULT CHARSET=utf8;
请注意,此表包含大约100 million
行,包含51GB的数据。
为什么我会获得锁定等待超时?我认为只有在运行多个查询时才会出现此错误。
答案 0 :(得分:0)
你已经尝试了很多方法,也许你可以试试:
创建索引book_type和json?也许这可以帮助一些人。
否则尝试拆分删除操作, 例如
DELETE
FROM books
WHERE
ID between 1 and 1000000
AND book_type = '/type/edition'
AND json LIKE '%"languages":%'
AND json NOT LIKE '%/eng%';
然后再次运行ID在1000001和2000000之间
等
答案 1 :(得分:0)
我做了同样的事情。看得很简单
DELETE FROM `database`.`table` WHERE ((action="limit") AND (info='login') AND (creation < DATE_SUB(NOW(), INTERVAL 10 MINUTE)))
也面临错误,然后按照:
您可以使用此行
在/etc/my.cnf中将其永久设置为更高的值[mysqld]
innodb_lock_wait_timeout=120
并重启mysql。如果此时无法重启mysql,请运行:
SET GLOBAL innodb_lock_wait_timeout = 120;
您也可以在会话期间设置
SET innodb_lock_wait_timeout = 120;