Backup MySQL databases in single file - Rocketeers app

  [ Rocketeers ](/)   

[Login](https://rocketeersapp.com/login) 

 On this page

 Knowledge
---------

Backup MySQL databases in single file
=====================================

### [\#Databases](https://rocketeersapp.com/knowledge/databases)

How to dump existing MySQL databases on a server in a single file.

 Published by [Mark van Eijk](https://rocketeersapp.com/author/mark-van-eijk) on January 12, 2023 
Updated on September 18, 2024 · 1 minute read

1. [MySQL backup bash script](#content-mysql-backup-bash-script)
2. [How to use](#content-how-to-use)

[\#](#content-mysql-backup-bash-script "Permalink")MySQL backup bash script
---------------------------------------------------------------------------

A clear and simple bash script to export all MySQL databases on your server into separate `.SQL` files.

With inline comments, this is the bash script to export all databases into separate files:

 ```
# MySQL username & password
USER=""
PASSWORD=""

# MySQL dump options
OPTIONS="--add-drop-table --extended-insert --single-transaction --skip-comments"

mysqldump --user="$USER" --password="$PASSWORD" $OPTIONS --all-databases > ./databases.sql

```

[\#](#content-how-to-use "Permalink")How to use
-----------------------------------------------

You can use this by copying the script, save it in an `backup.sh` file and then execute `chmod +x ./backup.sh` to give the file execution permissions.

Execute the script with `./backup.sh`.

### Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!

  Fill in your email address to receive updates  Subscribe 

#### More in [\#Databases](https://rocketeersapp.com/knowledge/databases)

- [Stream MySQL backup directly to S3 bucket](https://rocketeersapp.com/knowledge/stream-mysql-backup-s3-bucket)
- [Importing database in MySQL using command line](https://rocketeersapp.com/knowledge/import-database-mysql-command-line)
- [Export MySQL database using command line](https://rocketeersapp.com/knowledge/export-database-mysql-command-line)
- [How to upgrade MySQL 5.7 to 8.0 on Ubuntu](https://rocketeersapp.com/knowledge/upgrade-mysql-5-7-to-8-0-ubuntu)
- [Backup MySQL databases in separate files](https://rocketeersapp.com/knowledge/backup-mysql-databases-separate-files)
- [Backup MySQL databases except system databases in a single file](https://rocketeersapp.com/knowledge/backup-mysql-databases-except-system)

 [View all 20 articles →](https://rocketeersapp.com/knowledge/databases)
