最佳实践:将数百万条条目传输到另一个 MySQL 数据库

发布于 2025-01-04 13:21:13 字数 204 浏览 2 评论 0原文

我分配了以下任务:

获取一个包含多个表和数十万条条目的当前数据库,并编写一个脚本,将大部分数据传输到具有不同结构的单独数据库中。

基本上,已经使用不同的表结构创建了一个新数据库,我需要(在确认所有数据类型都匹配后)编写一个脚本将数据复制到正确的表/列。

最终我想知道对于如此大规模的数据传输是否有任何最佳实践、首选语言或有人可以提供的提示/技巧?

I have the following task assigned to me:

Take a current database, with multiple tables and hundreds of thousands of entries and write a script that will transfer much of this data to a separate database with a different structure.

Basically a new database has been created with a different table structure, and I need to (after confirming that all the datatypes will match up) write a script to copy the data over to the correct table/column.

Ultimately I was wondering on such a massive data transfer is there are any best practices, preferred languages, or hints/tips that someone could give?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

云胡 2025-01-11 13:21:13

首先,我认为最重要的一点是,您应该不惜一切代价避免编写任何将数据从生产服务器传输到另一个生产服务器的脚本。仅使用实时数据进行迁移的潜在危险就应该是足够的理由。

也就是说,我可以建议一些我认为可能适合此类任务的做法。

  1. 从生产服务器获取所有数据并将其转储到完全独立的开发盒中。消除对原始数据的风险以及对服务器性能的影响。
  2. 一旦进入严格的开发平台,我建议如果可能的话,将所有数据从 SQL 移动到 SQL,而不是使用某种中间语言编写脚本。当然,您的新结构可能完全禁止这种方法,但一般来说,必须担心将数据从严格的、可靠的数据类型移动到另一种语言(例如,无类型 PHP 或类型严格的 .net)。数据库增加了许多步骤,使您的任务变得复杂,增加了计算时间,并可能导致未捕获的损失。
  3. 只要有时间和能力,就花尽可能多的时间来验证新设计模式的智能性。除非您束手无策,否则请尝试想象这些更改实际上是否是改进,以及不可避免的查询重写是否提高了效率和可读性。

我确信还有许多其他事情需要注意,但我希望这些内容足以帮助您从一种模式过渡到另一种模式。如果本地服务器可行,然后导入,请不要让自己陷入远程服务器的困境。保持简单!

To start, I think the most important take-away is that you should at all costs avoid writing up any scripts that will transfer your data from a production server to another. The potential dangers of working with your live data for a migration alone should be enough reason.

That said, I can advise a few practices I think might be good for such a task.

  1. Take all the data from your production server and dump it to a devbox that is completely and entirely separate. Abolish the risk to your original data as well as performance impact to the server.
  2. Once on a strictly-development rig, I'd recommend if at all possible to keep all your data movement from SQL to SQL, rather than scripting it in some intermediary language. Of course, your new structure might be entirely prohibiting this sort of approach, but in general, having to worry about moving data from a strict, dependable datatype to another language (e.g., a typeless PHP or a type-strict .net) back to a database is adding a number of steps that complicate your task, add computational hours, and potentially uncaught lossiness.
  3. Spend as much time verifying the intelligence of the new design schema as you have time and power to do so. Unless your hands are tied, try to visualize if the changes are--in fact--improvements and that the inevitable query re-writes improve efficiency and readability.

I'm sure there are a number of other things to be looking out for, but I hope these are sufficiently helpful in helping you move from one schema to the next. Don't bog yourself down with remote servers if a local one is plausible and then import. Keep it simple!

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