How can I dump each mysql table separately with mysqldump?
Background: I want to track those dumps with git and using the pre-commit hook
Example: I have a schema with 10 tables (table1 - table10). now I want a file per table: table1.sql table2.sql ...
So how gonna this work?
Snd why stackoverflow don't like my question?
By default, the mysqldump utility, which allows to back a MySQL database, will perform a lock on all tables until the backup is complete.
To dump multiple tables with multiple where conditions. Then, for second table, use ">>". It will append the previous dump file.
We can export or copy data from one table to another table by using insert command. We can also use replace statement to copy data. We will try with insert command first.
The 'mysqldump' command is used to dump databases managed by MySQL. Let's consider three the most useful cases of MySQL database dumping. You can also specify several tables separated by whitespace to dump these tables only.
This should work in a shell:
for x in `mysql --skip-column-names -u [username] -p[password] [dbname] -e 'show tables;'`; do
mysqldump -u [username] -p[password] [db name] $x > "$x.sql"
done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With