如何合并两个相同结构的MySQL数据库 [英] How to merge two MySQL databases of same structure

查看:590
本文介绍了如何合并两个相同结构的MySQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是我的情况。我有我的当前数据库(我们称之为current_db)是最新的,但它的数据是不完整的,因为最近的崩溃。一些数据已删除,这个删除从2年前到昨天。

Here's my situation. I've got my current database (let's call it current_db) that is up to date, but its data are incomplete because of a recent crash. Some datas have been deleted, and this delete goes from 2 years ago to yesterday.

我有一个数据库的备份(我们称之为backup_db),从11月2013年,其数据已完成到2013年11月。由于current_db从2013年11月到2014年2月之间有一些数据,我不想只是废弃它,并从备份工作。所以我想导入current_db到backup_db忽略重复的数据。

I've got a backup of this database (let's call it backup_db), from November 2013, whose datas are complete up to November 2013. Since current_db holds some data from between November 2013 and February 2014, I don't want to just scrap it, and work from the backup. So I'd like to import current_db into backup_db ignoring duplicated data.

我已经搜索方法,但没有找到任何相关的。我遇到了一些SELECT查询,但他们都是简单的。我的数据库有20个表,我真的没有看到自己建立一个巨大的查询来导入所有这些。是否有其他方法?

I've seached for methods to do that, but couldn't find any relevant ones. I've come across a few SELECT queries, but they're all simplistic ones. My database holds 20 tables, and I don't really see myself building an immense query to import all of this. Is there any other way ?

感谢

推荐答案


  1. 使用phpMyAdmin(如果您仍然不使用,请安装)

  2. 转到当前数据库

  3. 数据库

可能的问题:


  • phpmyadmin中的最大文件上传大小可能为2MB。要解决此问题,请增加最大文件上传大小php.ini

  • The max file upload size in phpmyadmin may be 2MB.To solve this increase the maximum file upload size php.ini

假设您有模式s1和模式s2。

s1中的表格到s2中的表格中,而覆盖现有的行,可以使用:

To insert all rows of a table in s1 into a table in s2, while overwriting existing lines, you can use:

REPLACE INTO s2.table_name
SELECT * FROM s1.table_name;

如果您不想触摸现有的行:

If you do not want to touch existing lines:

INSERT INTO s2.table_name
SELECT * FROM s1.table_name
ON DUPLICATE KEY IGNORE;

如果您有任何问题,请在此留言。

Comment here if you have any issues.

这篇关于如何合并两个相同结构的MySQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆