Backup mysql databases into separate files
This bach script makes separate backup files of all the databases in mysql and saves the result in the mysql_backup folder.
#!/bin/bash -v USERNAME='yourusername' PASSWORD='yourpassword' HOSTNAME='yourhostname' BackupFolder='/backup' for i in $(echo 'SHOW DATABASES;' | mysql --user $USERNAME -p$PASSWORD -h $HOSTNAME | grep -v '^Database$' ); do mysqldump --user $USERNAME -p$PASSWORD -h $HOSTNAME --opt $i > $BackupFolder/$i.sql; done;
Remember to change the -h, -p and -h switch according to your needs and avoid space between -p and the password variable.