mysqldump entire structure but only data from selected tables in a single command

前端 未结 5 609
感情败类
感情败类 2021-01-30 05:39

My database has 3 tables: table1, table2 and table3

I would like to do a mysqldump on this database with the following conditions:

  • Dump structure for all t
5条回答
  •  不思量自难忘°
    2021-01-30 06:13

    Given you may want to pipe the output to another command, as I did, instead of just redirecting to a file and appending to that file in the next command, you could try (modified from the example of stask):

    (mysqldump -u $1 -p$2 -d db && mysqldump -u $1 -p$2 db --ignore-table=db.table3) |\
    your_command
    

    ... in my case:

    (mysqldump -u $1 -p$2 -d db && mysqldump -u $1 -p$2 db --ignore-table=db.table3) |\
    gzip -9 > filename.sql.gz
    

    Enclosing the two mysqldump commands in parentheses creates a subshell whose output we pipe into gzip and then redirect that into a file.

    PS: I've also been unable to combine it into one single mysqldump invocation, though.

提交回复
热议问题