MySQL克隆一个表,修剪一些数据,然后热交换它们的名称
我们有一个 800 万行的 MySQL 表。我们想要从中删除大约 200 万行,删除一些过时的索引并添加新索引。为了实现几乎没有停机时间,我们的计划是创建表的克隆(并锁定原始表),运行脚本(Ruby)来修剪我们不再需要的数据,最后添加新索引。然后我们将在网络应用程序上放置维护页面,交换它们的名称(通过重命名表)并重新启动应用程序。
这是实现最终结果的最佳方式吗?以前有过类似经历的人还有其他提示/建议吗?克隆表的最佳方法是什么(超级酷的秘密 mysql cmd)?批量删除行的最佳/最快方法?
We have a 8 million row MySQL table. We want to prune about 2m rows from it, remove some outdated indexes and add new ones. To achieve almost no downtime, our plan is to create a clone of the table (and lock the original), run a script (Ruby) to prune the data that we don't need anymore and finally add the new indexes. Then we would put up the maintenance page on the web app, swap their names (by renaming the tables) and restart the app.
Is this the best way to achieve our final results? Any other tips/suggestions from people that have some something similar to this before? Whats the best way (super cool secret mysql cmds) to clone the table? Best/quickiest way to mass delete rows?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
old_table
读取new_table
,不要带上要删除的记录记录< /em>new_table
new_table
替换old_table
old_table
处理 old_table当你想要的时候。
真正的问题是转换过程中的新数据,这通常意味着停机。希望您可以禁用添加数据的功能,而不是关闭整个站点。
old_table
new_table
, don't bring along records records to be deletednew_table
old_table
references withnew_table
old_table
Deal with old_table when you want.
The real problem is new data during the transition process, which generally means downtime. Hopefully, you can just disable the ability to add data rather than take the entire site down.