MySQL能创建两人相同的数据库吗_如果两个数据库都具有相同的模式,我可以将两个数据库合并到一个Mysql中吗?...

bd96500e110b49cbb3cd949968f18be7.png

I have two databases in MySQL that already have data. they have exactly the same schema. I would like to merge those two databases into one only. I tried:

mysqldump -u root -p --databases database1 database2 database3 > database1_database2_da

However, when I try to open database1_database2_da, I only end up with data from one of the database, but not all of them. I also want to mention that the two databases have their records starting at 1, since they are automatically generated. Do you think there is a way to merge those two databases without losing data from any of them?

解决方案

Run mysqldump on each database with the --no-create-info option to avoid writing schema information. Then run once on one database with the --no-data option. If you load all of these files sequentially into the same target database, this should work, barring any differences in schema between the two databases or duplicate primary keys.

mysqldump -u root -p --no-create-info database1 > database1.sql

mysqldump -u root -p --no-create-info database2 > database2.sql

mysqldump -u root -p --no-data database1 > schema.sql

After creating a new database, run

mysql -uroot -p -Ddatabase3 < schema.sql

mysql -uroot -p -Ddatabase3 < database1.sql

mysql -uroot -p -Ddatabase3 < database2.sql

This may also work. Don't have a Windows box to test on ATM

type schema.sql database1.sql database2.sql | mysql -uroot -p -Ddatabase3

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值