MySQL import - How to ignore Drop table if exists line?

后端 未结 3 1802
走了就别回头了
走了就别回头了 2021-02-13 12:57

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

相关标签:
3条回答
  • 2021-02-13 13:13

    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>
    

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

    0 讨论(0)
  • 2021-02-13 13:13

    I guess I don't see why a DROP TABLE statement should be problematic or why you need to merge dumps for two IDENTICAL databases.

    That being said, you should probably just not add DROP TABLE in the initial dump. This would be controlled via flag use in your mysqldump command as noted in the documention at http://dev.mysql.com/doc/refman/5.5/en/mysqldump.html

    This probably means you need to use --skip-opt flag if you were using default options (default is to run as if --opt flag is passed). You will then need to specify all flags within --opt that you still want to use.

    0 讨论(0)
  • 2021-02-13 13:28

    All you need is add --skip-add-drop-table option when using mysqldump.

    $ mysqldump --databases --skip-add-drop-table -u root db1 > /tmp/qqq.2
    

    So, there would not DROP TABLE IF EXISTS in sql files.

    see docs of mysql on --skip-add-drop-table

    0 讨论(0)
提交回复
热议问题