mysql dump - exclude some table data

后端 未结 8 1336
独厮守ぢ
独厮守ぢ 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 am a new user, and do not have enough reputation to vote or comment on answers, so I am simply sharing this as an answer.

    @kantholy clearly has the best answer.

    @AmitP's method dumps all structure and data to a file, and then a drop/create table statement at the end. The resulting file will still require you to import all of your unwanted data before simply destroying it.

    @kantholy's method dumps all structure first, and then only data for the table you do not ignore. This means your subsequent import will not have to take the time to import all the data you do not want - especially important if you have very large amounts of data you want to ignore to save time.

    To recap, the most efficient answer is:

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

提交回复
热议问题