重新架构 MySQL 索引
由于之前糟糕的索引设计,我必须重新构建索引结构。 我有大约 200 个表,每个表有几千到 2000 万行。 在生命系统上手动删除索引并创建新索引需要花费几天的时间。
所以这是我的想法:
我删除架构(备份后;)
创建一个新架构
使用 CREATE TABLE 语句运行一个完整的系列,声明所需的主键和索引(需要一分钟左右)
将数据库的 RESTORE 运行到该新架构中(这可能需要 2 小时 - 但不是几天)
)这有道理吗?
I have to re-architect the index structure because of previously bad index design.
I have some 200 tables with a few thousand up to 20 million rows per table.
It would take days to manually remove indexes and create new indexes on the life system.
So here is my thought:
I erase the schema (after backup ;)
Create a new schema
Run a complete series with CREATE TABLE statements declaring the needed Primary Keys and indexes (takes a minute or so)
Run a RESTORE of the DB into that new schema (This may take 2 hours - but not days)
Does that make sense?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您提出的解决方案是类似的,但您可以启动一个新的复制从属服务器,然后首先对该计算机上的架构进行更改。只要您仅对索引进行更改,那么事件将继续重新应用,不会出现错误。
更改完成后,您可以 1) 将从站升级为主站,在从站上应用相同的更改,然后切换回来或 2) 停止两个 MySQL 实例并将原始数据文件从从站复制到主站。
使用这种方法,索引仍然会重建,但在从属服务器上进行更改需要多长时间确实很重要。唯一的停机时间是复制文件所需的时间。
还有其他解决方案可以在不使用从属设备的情况下对表执行非阻塞更改,例如 Oak-online-alter-table http://openarkkit.googlecode.com/svn/trunk/openarkkit/doc/html/oak-online-alter-table.html 以及 Facebook 开发的类似工具http://www.facebook.com/notes/mysql-at-facebook/online-schema-change-for-mysql/430801045932。
I think you're proposed solution is similar, but you could start up a new replication slave and then make the changes to the schema on that machine first. As long as you are only making changes to indexes then events will continue to be re-applied with no errors.
Once the changes have completed you could then 1) promote slave to master, apply same changes on slave and then switch back or 2) stop both MySQL instances and copy across the raw data files from the slave to the master.
Using this method, the indexes are still rebuilt but it does really matter how long it takes to make the changes on the slave. The only downtime is length of time it takes to copy the files across.
There are other solutions out there that can perform non-blocking changes to tables without use of a slave such as oak-online-alter-table http://openarkkit.googlecode.com/svn/trunk/openarkkit/doc/html/oak-online-alter-table.html and a similar tool developed by Facebook http://www.facebook.com/notes/mysql-at-facebook/online-schema-change-for-mysql/430801045932.