Skip to main content

How do I make a backup of the database?

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.

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.

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

To restore an uncompressed database, use the following command:

mysql -u user_name -p database_name < db.sql