12

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?

2
  • What do you mean with Snd why stackoverflow don't like my question? Commented Feb 20, 2012 at 9:48
  • 3
    stackoverflow.com/questions/3669121/… Commented Oct 3, 2013 at 17:00

2 Answers 2

36

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 
Sign up to request clarification or add additional context in comments.

2 Comments

Actually Naveen Kumar's answer is better than mine.
No, your answer is better :) thanx
1
mysqldump -t -u [username] -p test mytable 

will dump the table 'mytable' from the database 'test'.

If you want to automate the procedure, you will need to write a script, that selects the table_names from the schema for you and apply the operation above for each table. You can automate the git operations as well.

1 Comment

Depends on your operation system. If you're using Linux - bash scripting probably.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.