MySQL克隆一个表,修剪一些数据,然后热交换它们的名称

发布于 2024-09-13 12:48:24 字数 262 浏览 0 评论 0原文

我们有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温柔一刀 2024-09-20 12:48:24
  1. 所有引用都使用视图,而不是直接从old_table读取
  2. 创建new_table
  3. 选择所需记录放入new_table不要带上要删除的记录记录< /em>
  4. 索引 new_table
  5. 更新视图,用 new_table 替换 old_table
  6. 引用 重命名 old_table

处理 old_table当你想要的时候。

真正的问题是转换过程中的新数据,这通常意味着停机。希望您可以禁用添加数据的功能,而不是关闭整个站点。

  1. All references use a view, not reading directly from old_table
  2. Create new_table
  3. Select desired records into new_table, don't bring along records records to be deleted
  4. Index new_table
  5. Update view, replace old_table references with new_table
  6. Rename 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文