mysqldump entire structure but only data from selected tables in a single command
You can't combine them in one command but you can execute both commands at the same time and output to the same file.
mysqldump -u user -p --no-data db > structure.sql; mysqldump -u user -p db table1 table2 >> structure.sql
to avoid having to enter the password twice you can do -ppassword
(note the lack of space!). Also use --no-data
in the first command or you end up with the data as well. -d isn't needed when you're doing just one database.
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.