更改架构时如何加快 MySQL 中的表重建速度?
我有一个相对较大的 MySQL InnoDB 表(已压缩),有时需要更改其架构(增加列大小或添加字段)。
对于一个包含数百万行的 500 MB 表大约需要 1 小时,但服务器似乎不是很忙(CPU @5%,使用的 RAM 不多,I/O 为 2.5 MB/s)。
该表未在生产中使用,因此不会同时发生并发请求。只有一个主索引(前 5 列)和一个外键约束。
您对如何加快表更改过程有什么建议吗?
I have a relatively big MySQL InnoDB table (compressed), and I sometimes need to alter its schema (increasing column size or adding a field).
It takes around 1 hour for a 500 MB table with millions of rows, but the server doesn't seem to be very busy (CPU @5%, not much RAM used, and 2.5 MB/s as I/O).
The table is not used in production so there are no concurrent requests at the same time. There is only a primary index (on the first 5 columns) and one foreign key constraint.
Do you have any suggestion on how to speed-up the table alteration process?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更改存储引擎(更换为新一代引擎,例如 TokuDB)似乎是可行的方法,直到 InnoDB 被“修复”。
Changing storage engine (to newer generation engines like TokuDB) seems the way to go, until InnoDB is "fixed".
了解确切的表和主键/索引定义会很有帮助,而不太重要的是,行数精确到百万,尽管我猜测该表只有 500mb,可能少于 2000 万行。另外,您更改表的方法 - 您是创建一个新模式并插入其中,还是使用更改表等。
我之前在这方面取得了成功,采用了
Would be helpful to know the exact table and primary key/index definitions, and of lesser importance, the row count to the nearest million, although I would guess as the table is only 500mb it's probably less than 20 million rows. Also, your approach to changing the table - are you creating a new schema and inserting into it, or using a alter table etc.
I've had success in this area before with approaches like