Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysqldumper: Dumping each table separately

Tags:

git

mysql

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?

like image 669
Nils Rückmann Avatar asked Feb 20 '12 09:02

Nils Rückmann


People also ask

Can Mysqldump lock tables?

By default, the mysqldump utility, which allows to back a MySQL database, will perform a lock on all tables until the backup is complete.

How do I dump multiple tables in MySQL?

To dump multiple tables with multiple where conditions. Then, for second table, use ">>". It will append the previous dump file.

How do I dump data from one table to another table?

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.

How do you dump a table?

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.


1 Answers

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
like image 90
Edson Medina Avatar answered Nov 12 '22 23:11

Edson Medina