mysql dump - exclude some table data

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

    To further improve on kantholy's answer, adding compression and removing most of the disk writes by not writing uncompressed data:

    #!/bin/bash
    echo -n "db name:"
    read -r db_name
    echo -n "username:"
    read -r username
    echo -n "Exclude data from table:"
    read -r exclude_table_data
    
    {
     mysqldump "$db_name" --user="$username" --password --no-tablespaces --no-data \
     && \
     mysqldump "$db_name" --user="$username" --password --no-tablespaces --no-create-info \
     --ignore-table="${db_name}.${exclude_table_data}";
    } \
    | bzip2 -c9 \
    > "${db_name}_$(date +%y%m%d_%H%M).sql.bz2"
    

提交回复
热议问题