如何合并两个相同结构的MySQL数据库

编程入门 行业动态 更新时间:2024-10-10 05:16:58
本文介绍了如何合并两个相同结构的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 ?

感谢

推荐答案

  • 使用phpMyAdmin(如果您仍然不使用,请安装)
  • 转到当前数据库
  • 数据库
  • 可能的问题:

    • 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数据库

    本文发布于:2023-11-29 04:24:46,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1645266.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:两个   结构   数据库   MySQL

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!