# How to Create a Database Backup

<div id="bkmrk-almost-every-modern-"><section class="wpb-content-wrapper">Almost every modern website uses a MySQL database. More popular content management systems, such as WordPress, Magento, Joomla, store all data in a MySQL database. If, for some reason, we want to back up the database, such as a MySQL server update, then it is possible to extract the data stored in the database or to recover the dump in case of a possible error.

#### COMPRESS A FOLDER

After you connect to the server via SSH, you can create a backup by issuing the following command:

```
mysqldump -u user_name -p database_name --single-transaction | gzip -2 > db.sql.gz
```

By issuing the above command, you create a compressed dump with a single transaction token.

<p class="callout info"><span class=".">Of course, it is also possible to make an uncompressed dump, but it will take a lot more time and more space will be spent on dumped content.</span></p>

```
mysqldump -u user_name -p database_name > db.sql
```

#### EXTRACT AN ARCHIVE

You can do this by issuing the following command

```
gunzip < db.sql.gz | mysql -u user_name -p database_name


```

<div class="vc_row wpb_row vc_row-fluid"><div class="wpb_column vc_column_container vc_col-sm-12"><div class="vc_column-inner"><div class="wpb_wrapper"><div class="wpb_text_column wpb_content_element "><div class="wpb_wrapper">  
</div><span class=".">To restore an uncompressed database, use the following command:</span></div></div></div></div></div></section></div>```
mysql -u user_name -p database_name < db.sql
```

<div id="bkmrk-"></div>