mysql dump - exclude some table data

后端 未结 8 1335
独厮守ぢ
独厮守ぢ 2021-01-30 10:40

Is it possible, using mysql dump to export the entire database structure, but exclude certain tables data from export.

Say the database has 200 tables, I wish to export

相关标签:
8条回答
  • 2021-01-30 10:59

    This will produce export.sql with structure from all tables and data from all tables excluding table_name

    mysqldump --ignore-table=db_name.table_name db_name > export.sql
    mysqldump --no-data db_name table_name >> export.sql
    
    0 讨论(0)
  • 2021-01-30 11:04

    Previous answers don't fix the issue with the AUTO_INCREMENT when we export the structure and don't show how to export some specific data in tables.

    To go further, we must do :

    1/ Export the structure

    mysqldump --no-data db_name | sed 's/ AUTO_INCREMENT=[0-9]*\b//g' > export-structure.sql
    

    2/ Export only data and ignores some tables

    mysqldump --no-create-info --ignore-table=db_name.table_name1 [--ignore-table=db_name.table_name2, ...] db_name >> export-data.sql
    

    3/ Export specific data in one table

    mysqldump --no-create-info --tables table_name --where="id not in ('1', '2', ...)" > export-table_name-data.sql
    

    I tried to use the --skip-opt option to reset AUTO_INCREMENT but this also delete the AUTO_INCREMENT definition on the field, the CHARSET and other things

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