七度&光 2009-01-08 17:30 采纳率: 22.2%
浏览 872
已采纳

使用 mysqldump 忽略某些表

Is there a way to restrict certain tables from the mysqldump command?

For example, I'd use the following syntax to dump only table1 and table2:

mysqldump -u username -p database table1 table2 > database.sql

But is there a similar way to dump all the tables except table1 and table2? I haven't found anything in the mysqldump documentation, so is brute-force (specifying all the table names) the only way to go?

转载于:https://stackoverflow.com/questions/425158/skip-certain-tables-with-mysqldump

  • 写回答

6条回答 默认 最新

  • lrony* 2009-01-08 17:33
    关注

    You can use the --ignore-table option. So you could do

    mysqldump -u USERNAME -pPASSWORD --ignore-table=database.table1 > database.sql
    

    There is no whitespace after -p (this is not a typo).

    If you want to ignore multiple tables you can use a simple script like this

    #!/bin/bash
    PASSWORD=XXXXXX
    HOST=XXXXXX
    USER=XXXXXX
    DATABASE=databasename
    DB_FILE=dump.sql
    EXCLUDED_TABLES=(
    table1
    table2
    table3
    table4
    tableN   
    )
    
    IGNORED_TABLES_STRING=''
    for TABLE in "${EXCLUDED_TABLES[@]}"
    do :
       IGNORED_TABLES_STRING+=" --ignore-table=${DATABASE}.${TABLE}"
    done
    
    echo "Dump structure"
    mysqldump --host=${HOST} --user=${USER} --password=${PASSWORD} --single-transaction --no-data --routines ${DATABASE} > ${DB_FILE}
    
    echo "Dump content"
    mysqldump --host=${HOST} --user=${USER} --password=${PASSWORD} ${DATABASE} --no-create-info --skip-triggers ${IGNORED_TABLES_STRING} >> ${DB_FILE}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大