10.24 2009-01-08 17:30 采纳率: 0%
浏览 343
已采纳

使用 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条回答 默认 最新

  • csdnceshi62 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条)

报告相同问题?

悬赏问题

  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码