1

I run the following query and it is the only query running on my large (2 vCPU, 7.5 GB RAM, 100GB SSD) RDS hosted database.

DELETE
FROM books
WHERE book_type = '/type/edition'
AND json LIKE '%"languages":%'
AND json NOT LIKE '%/eng%';

But I get the following error.

Error Code: 1205. Lock wait timeout exceeded; try restarting transaction

I increased the timeout to 1200 seconds using SET innodb_lock_wait_timeout = 1200;.

However, I get that same error. There are no other queries running on the database, it's newly created and not in production. Here is the result of 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                                                                                     |
+---+----------+----------------------------------------------------------+-------------+-------+-----+----------+------------------------------------------------------------------------------------------------------+

Here is the schema for this table.

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;

Please note, this table has about 100 million rows and contains 51GB of data.

Why am I getting a lock wait timeout? I thought this error could occur only when you are running multiple queries.

5
  • obviously your query is too heavy, can you try to split it up? also mysql workbench is using transactions by default, you can try to run query from mysql prompt
    – Peter
    May 1, 2015 at 11:30
  • SET GLOBAL innodb_lock_wait_timeout = 5000; and SET innodb_lock_wait_timeout = 5000; May 1, 2015 at 11:38
  • This started happening to me when my database size grew and i was doing a lot of transactions on it. Truth is there is prob some way to optimize either your queries or your DB but try these 2 queries for a work around fix. May 1, 2015 at 11:38
  • @Peter I switched to sequelpro and it gave me the same error as mysql workbench. What do you mean by split up query? Do you mean limiting to certain rows like @Ravi suggested?
    – Abs
    May 1, 2015 at 11:43
  • yes, split it up using BETWEEN
    – Peter
    May 1, 2015 at 11:55

2 Answers 2

0

Well as you have tried most ways, maybe you could try :

create index book_type and json ? Maybe this can help some.

Otherwise try to split the delete operation, e.g.

DELETE
FROM books
WHERE 
ID between 1 and 1000000 
AND book_type = '/type/edition'
AND json LIKE '%"languages":%'
AND json NOT LIKE '%/eng%';

and then run again where ID between 1000001 and 2000000

etc.

0

I have do same thing. see it very simple way

DELETE FROM `database`.`table` WHERE ((action="limit") AND (info='login') AND (creation < DATE_SUB(NOW(), INTERVAL 10 MINUTE)))

also face error then follow:

You can set it to higher value in /etc/my.cnf permanently with this line

[mysqld]
innodb_lock_wait_timeout=120

and restart mysql. If you cannot restart mysql at this time, run this:

SET GLOBAL innodb_lock_wait_timeout = 120; 

You could also just set it for the duration of your session

SET innodb_lock_wait_timeout = 120; 
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.