How To Backup MySQL Databases on Ubuntu

What is MySQL?

MySQL, the most popular Open Source SQL database management system, is developed, distributed, and supported by Oracle Corporation.
The MySQL Web site ( provides the latest information about MySQL software.

How to Backup a MySQL Database into 1 File:

Run this command:

mysqldump -u username -p database_to_backup > backup_name.sql

How to Backup MySQL Database into Many Files:

date=$(date +%Y%m%d);
Year=$(date +%Y);
Month=$(date +%m);
Day=$(date +%d);
mysql -s -r -u USERNAME -pYOURPASSWORD -e 'show databases' | while read db; do mysqldump -u USERNAME -pYOURPASSWORD $db -r /var/lib/backups/mysql-backup/backup-"$Day"-"$Month"-"$Year"/${db}.sql; [[ $? -eq 0 ]] && gzip /var/lib/backups/mysql-backup/backup-"$Day"-"$Month"-"$Year"/${db}.sql; done

Share this post

Comments (1)

  • Venelin Vasilev


    2017-04-14 03:16:02

To post comments you must have account with VivasHost! To create an Account you must purchase any service you want.

Take a look at our VPS - Virtual Private Servers or our Dedicated Servers.