简体   繁体   English

用PHP将多个mssql数据库合并到一个mysql

[英]Combine several mssql database to one mysql with php

We are handling a data aggregation project by having several microsoft sql server databases combining to one mysql database. 我们正在通过将多个Microsoft sql服务器数据库合并到一个mysql数据库来处理数据聚合项目。 all mssql database have the same schema. 所有mssql数据库都具有相同的架构。

The requirements are : 要求是:

  • each mssql database can be imported to mysql independently 每个mssql数据库都可以独立导入mysql
  • before being able to import each record to mysql we need to validates each records with a specific createrias via php. 在能够将每个记录导入mysql之前,我们需要通过php使用特定的createrias验证每个记录。

  • each imported mssql database can be rollbacked. 每个导入的mssql数据库都可以回滚。 It means even it already imported to mysql, all the mssql database can be removed from the mysql. 这意味着即使已经将其导入到mysql,也可以从mysql中删除所有mssql数据库。

  • we would still like to know where does each record imported to the mysql come from what mssql database. 我们仍然想知道导入到mysql的每条记录从哪里来的mssql数据库。

    All import process will be done with PHP . 所有导入过程都将使用PHP完成。

    we have difficulty in many aspects. 我们在很多方面都有困难。 we don't know what is the best approach to solve our problem. 我们不知道解决问题的最佳方法是什么。

    your help will be highly appreciated. 非常感谢您的帮助。

    ps: each mssql database has around 60 tables and each table can have a few hundred thousands . ps:每个mssql数据库大约有60个表,每个表可以有几十万个。

Don't use PHP as a database administration utility. 不要将PHP用作数据库管理实用程序。 Any time you build a quick PHP script to transfer records directly from one database to another, you're going to cause yourself a world of hurt when that script becomes required for production operation. 每当您构建一个快速的PHP脚本以将记录直接从一个数据库直接传输到另一个数据库时,当生产操作需要该脚本时,就会给自己造成很大的伤害。

You have a number of problems that you need solved: 您有许多需要解决的问题:

  • You have multiple MSSQL databases with similar if not identical tables. 您有多个MSSQL数据库,这些数据库具有相似的表(如果不相同)。
  • You have a single MySQL database that you want to merge the data into. 您想要将数据合并到一个MySQL数据库中。
  • The imported data must be altered in a specific way before being merged. 在合并之前,必须以特定的方式更改导入的数据。
  • You want to prevent all duplicate records in your import. 您要防止导入中所有重复的记录。
  • You want to know what database each record originally came from. 您想知道每个记录最初来自哪个数据库。

The solution? 解决方案?

  1. Analyze the source MSSQL databases and create a merge strategy for them. 分析源MSSQL数据库并为其创建合并策略。
  2. Create a database structure on the MySQL database that fits the merge strategy in #1, including all the new key constraints (like unique and foreign keys) required for the consolidation. 在适合#1的合并策略的MySQL数据库上创建数据库结构,包括合并所需的所有新键约束(如唯一键和外键)。

At this point you have two options left: 至此,您还有两个选择:

  1. Dump the data from each of the source databases into raw data using your RDBMS administration utility of choice. 使用所选的RDBMS管理实用程序将每个源数据库中的数据转储到原始数据中。 Alter that data to fit your merge strategy and constraints. 更改数据以适合您的合并策略和约束。 Document this, and then merge all of the data into your new database structure. 对此进行记录,然后将所有数据合并到新的数据库结构中。
  2. Use a tool like opendbcopy to map columns from one database to another and run a mass import. 使用opendbcopy之类的工具将列从一个数据库映射到另一个数据库,然后运行批量导入。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM