优化MySql 5.7表而无需停机 [英] Optimize MySql 5.7 table without downtime

查看:165
本文介绍了优化MySql 5.7表而无需停机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MySql 5.7服务器中有一个表。我们每天存储约100万行。每次插入行后,我们都会对该行进行一些处理,然后删除该行。

I have a table in MySql 5.7 server. We store around 1M rows every day. After each row insertion, we do some processing on that row after that we delete that row.

由于大量的写操作,表磁盘空间正在迅速增加。因此,我想对表进行优化。

Table disk space is rapidly increasing because of this huge number of write operations. So I want to do OPTIMIZE the Table.

因此,如果我在生产表上应用OPTIMIZE Table命令,它将导致任何停机时间。

So if I apply OPTIMIZE Table command on production table does it give any downtime.

做优化表的最好方法是什么?

What is the best way to do OPTIMIZE table?

MySql Server详细信息

服务器版本: 5.7

引擎: InnoDB

托管: Google Cloud Sql

谢谢

推荐答案

是的,是的,从MySQL 5.6.17或更高版本开始,OPTIMIZE TABLE将在适当的位置执行工作。我们可以在以下文档中找到有关此文档的信息:有关这些文档的操作支持在线DDL,请参见: https://dev.mysql.com/doc/refman/5.6/en/innodb-create-index-overview.html

Yes, you're right, OPTIMIZE TABLE will perform the work in place as of MySQL 5.6.17 or later. We find this note in the documentation on which operations support online DDL here: https://dev.mysql.com/doc/refman/5.6/en/innodb-create-index-overview.html

您可以尝试对此进行测试(我在您的评论后做了):

You can experiment to test this (I did after your comment):


  1. 创建一个表,并在其中填充数十万行

  2. 运行优化表,因为该大小的表将花费20-30秒或更长时间。

  3. 正在运行时,请打开第二个窗口,然后对表尝试SELECT,INSERT,UPDATE或DELETE。您会发现它不会阻止DML。

如果您的ALTER TABLE不能作为在线DDL使用,则可以免费使用工具 pt-online-schema-change 有助于避免锁定行为,即使对于表重组操作也是如此。该工具不会锁定表格,但会创建触发器,以便在复制所有行时捕获所有更改并将其应用于新的复制表格。

If you do have an ALTER TABLE that cannot work as online DDL, there's a good free tool pt-online-schema-change that help to avoid locking behavior even for table-restructure operations. This tool does NOT lock the table, but it creates triggers so any changes are captured and applied to the new copy table while it's in progress of copying all the rows.

这篇关于优化MySql 5.7表而无需停机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆