Mysql解决The total number of locks exceeds the lock table size错误

♀尐吖头ヾ 提交于 2020-11-24 12:27:13

Mysql解决The total number of locks exceeds the lock table size错误

在本地UPDATE 一百万条数据的某个字段时,第一次正确修改了,第二次爆出 The total number of locks exceeds the lock table size 错误

引用下网上的解释

If you're running an operation on a large number of rows within a table that uses the InnoDB storage engine, you might see this error: ERROR 1206 (HY000): The total number of locks exceeds the lock table size MySQL is trying to tell you that it doesn't have enough room to store all of the row locks that it would need to execute your query. The only way to fix it for sure is to adjust innodb_buffer_pool_size and restart MySQL. By default, this is set to only 8MB, which is too small for anyone who is using InnoDB to do anything. If you need a temporary workaround, reduce the amount of rows you're manipulating in one query. For example, if you need to delete a million rows from a table, try to delete the records in chunks of 50,000 or 100,000 rows. If you're inserting many rows, try to insert portions of the data at a single time.

原来是InnoDB表执行大批量数据的更新,插入,删除操作时会出现这个问题,需要调整InnoDB全局的innodb_buffer_pool_size的值来解决这个问题,并且重启mysql服务。 查看当前数据库存储引擎,在创建时使用 ENGINE=InnoDB类型。 默认的innodb_buffer_pool_size=8M

#查看MySQL的存储引擎
mysql> show variables like '%storage_engine%';
+----------------------------------+--------+
| Variable_name                    | Value  |
+----------------------------------+--------+
| default_storage_engine           | InnoDB |
| default_tmp_storage_engine       | InnoDB |
| disabled_storage_engines         |        |
| internal_tmp_disk_storage_engine | InnoDB |
+----------------------------------+--------+
4 rows in set, 1 warning (0.00 sec)

#查看MySQL缓存池的大小
#可以看到,默认的缓存池大小是 8388608 = 8 * 1024 * 1024 = 8 MB。需要把它改大一点。
mysql> show variables like "%_buffer_pool_size%";
+-------------------------+---------+
| Variable_name           | Value   |
+-------------------------+---------+
| innodb_buffer_pool_size | 8388608 |
+-------------------------+---------+
1 row in set, 1 warning (0.00 sec)

#修改innodb_buffer_pool_size
mysql> SET GLOBAL innodb_buffer_pool_size=2147483648;
#改为2g.
#注意mysql5.7版本之后的修改即生效,以前版本的得修改my.cnf再重启。
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!