mysql dump - exclude some table data

后端 未结 8 1350
独厮守ぢ
独厮守ぢ 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:54

    I think that AmitP's solution is great already - to improve it even further, I think it makes sense to create all tables (structure) first and then fill it with data, except the ones "excluded"

    mysqldump --no-data db_name > export.sql
    mysqldump --no-create-info --ignore-table=db_name.table_name db_name >> export.sql
    

    if you want to exclude more than 1 table, simply use the --ignore-tabledirective more often (in the 2nc command) - see mysqldump help:

    --ignore-table=name   Do not dump the specified table. To specify more than one
                          table to ignore, use the directive multiple times, once
                          for each table.  Each table must be specified with both
                          database and table names, e.g.,
                         --ignore-table=database.table
    

提交回复
热议问题