Mysql – Deleting MySQL rows causes lock table error

databaseMySQLsql

I had a couple million rows to delete but they can't be deleted at once without this error

ERROR 1206 (HY000): The total number of locks exceeds the lock table size

So I wrote a script to delete 100,000 rows 10,000 at a time. It ran once but when I run it a second time I get the error on the first attempt to delete 10,000.

The way I'm trying to delete the 10,000 rows is to use a delete statement that refers to all 2 million rows but I use a limit clause to affect only 10,000.

I've tried adding an "unlock tables;" statement to the script before the first delete but that doesn't help. I still get the lock table error on the first delete.

Any ideas how I can do this?

Is there a way I can tell it NOT to lock records? I can make sure nothing else is accessing the table.

Best Answer

Is it the InnoDB storage engine?

This error means that MySQL doesn't have enough room to store all of the rows lock that it would need to execute your query. Depend on RAM you have, set innodb_buffer_pool_size to a reasonable value (256MB, 512MB), you will probably never encounter this error.

Check the default value with mysql> show global variables like 'innodb_buffer%';.

Related Topic