Backup All MySQL Databases on Linux Server
What you will need:
- Access to the server’s Linux shell with root (or sudo) user privileges.
- MySQL root user password.
Process description:
This process backup all MySQL databases available on the server. For each database, an individual backup is generated in SQL format. Each file is then compressed (.gz), using the database name followed by the execution date as the file name (e.g., mydatabase_2025-06-27.gz). This facilitates organization, specific recovery, and versioning of backups.
Creating the shell file for backup
Create a file in the Linux shell:
Paste the following content into this file:
save the file and exit nano (ctrl+x, y, enter)
Edit the file you created and change the line below with the mysql root password:
save the file and exit nano (ctrl+x, y, enter)
Change the file permissions:
By default, the backup will be created in /backup/mysql. If you wish, you can change the location to save the file by editing the created file and changing BACKUP_DIR=”/backup/mysql”.
Running the backup:
Run the file and wait for the process to complete:
This is a simple but very useful script for backing up all MySQL databases on a Linux server.