导入数据并保留 ID 和关系
我正在努力清理另一个程序员造成的混乱。他们为不同的位置创建了两个相同的数据库,但这显然导致了重大问题。他们正在使用cakePHP并且有相当多的关系。我很确定我必须编写一个脚本来将数据从数据库导入到另一个数据库并保留所有关系,但想知道是否有更简单的方法来做到这一点。
I am working on cleaning up a mess that another programmer started. The created 2 identical databases for different locations but that obviously caused major issues. They are using cakePHP and there are quite a few relationships. I am pretty sure I will have to write a script to import that data from on DB to the other and keep all the relationships but was wondering if there is an easier way to do it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用哪个数据库?数据库的记录有多大?
想法 #1
像 RedGate 的 SQL Data Compare 这样的工具怎么样?它比较两个数据库之间的数据并让您同步它们。
我过去一直使用这个工具来同步不同生产数据库之间的更改,它的效果就像梦想一样。 RedGate 的 sql 工具是一流的(完全不隶属于它们)。
SQL 数据比较: http://www.red-gate.com/products/ sql_data_compare/index.htm
想法 #2
如果存在大量关系,您必须禁用外键约束才能导入所有数据。完成此操作后,您可以一次导入一张表的数据。如果您使用的是 mysql 这样的数据库,请使用 mysqldump 创建 sql 插入。创建脚本的过程大部分是自动化的。但仍然是繁重的工作。
Which database are you using? How big are the databases in terms of records?
Idea #1
What about a tool like RedGate's SQL Data Compare? It compares the data between two databases and lets you synchronize them.
I used to use this tool all the time to synchronize changes between different production db's and it works like a dream. RedGate's sql tools are top notch (not affiliated with them at all).
SQL Data Compare: http://www.red-gate.com/products/sql_data_compare/index.htm
Idea #2
You'll have to disable foreign key constraints to import all the data if there are lots of relationships. Once you do that you can import the data one table at a time. If you are using a database like mysql, use mysqldump to create the sql inserts. The process of creating a script is mostly automated for you. Still grunt work though.