MySQL database backup

Once in a while we all need to keep backup of all the MySQL databases in our system. We can easily do that with mysqldump, but one small issue with mysqldump is that it generate a dump of all databases into a huge single file. Here i’ll show you how to keep backup of every database in separate file using the same tool. I will breakdown the process in steps.
In step 1 i will generate a list of available database and save them in a file called db-list.txt
In step 2 i will read the database name from that file (db-list.txt) one by one and generate a sql dump for that database.
Let’s do it.

Step 1:

mysql -u root -p -e "show databases" > db-list.txt

Step 2:

for /f %a in (db-list.txt) do (mysqldump -u root -p %a > %a.sql)


About uzzal

Software developer
This entry was posted in MySQL, Tips & Tricks and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s