MySQL导入-如果存在行,如何忽略Drop table? [英] MySQL import - How to ignore Drop table if exists line?

查看:325
本文介绍了MySQL导入-如果存在行,如何忽略Drop table?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用mysqldump将2个相同的数据库(在名称和表结构方面相同)导出到两个.sql文件中.我想将它们合并到一个文件中.但是,两个数据库在每个表之前都有"Drop table"行.这意味着如果我先导入db1,然后再导入db2,则在导入db2表之前先删除db1表.

I exported 2 identical databases(identical in terms of names and structures of tables) into two .sql files using mysqldump. I want to merge them into one file. However, both the databases have a 'Drop table' line before every table. What that means is if I import db1 and then db2, db1 tables are dropped before db2 tables are imported.

文件很大,我无法在编辑器中打开它们.此外,每个数据库中有50个表.

The files are huge and I am not able to open them in the editor. Also, there are 50 tables in each databases.

在mysql导入期间如何忽略Drop table命令?

How can I ignore the Drop table command during mysql import?

推荐答案

如果您不想再次进行转储,而您正在使用Linux,则可以使用:

If you do not want to make dump once again and you are using Linux you can go with:

awk '!/^DROP TABLE IF EXISTS/{print}' <dump.file> | mysql <db_name>

如果要再次转储数据,则应将--skip-add-drop-table传递给mysqldump实用程序.

If you want to dump data once again you should pass --skip-add-drop-table to mysqldump utility.

这篇关于MySQL导入-如果存在行,如何忽略Drop table?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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