MySQL: Export Each Database to Individual SQL File

MySQL backups are normally done using mysqldump – a MySQL database backup program. The problem is all the backups will be written to a single output SQL file. I prefer to dump each MySQL database to a separate SQL file.

To suit my requirements, I wrote a small shell script to dump MySQL databases to separate SQL files. Below is the script.

A sample output the script is shown below.

The script will not export databases specified in the “db_to_skip” variable. You can modify the variable to suit your requirements.

I have only tested the script on Linux on bash shell. Modifications might be required to run the script on other UNIX distributions – especially on the grep and read commands.

Do take note that when the shell script is running, there is a chance that a logged in user could view the specified username and password of the MySQL server by running the ps command.

ibrahim = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, php, python, java, javascript, nodejs, react); plays_on(xbox, ps4); linux_desktop_user(true); }