[TUTORIAL] How to backup database with mysqldump - EXPORT and IMPORT your database

  • MAKE A BACKUP | EXPORT

1. Get the privileges:

Access your terminal via SSH with root

2. Create the backups folder and access the path:

$ cd /home && mkdir db-backups && cd db-backups

3. Export your database:

$ mysqldump -u [user-name] -p [db-name] > backup-my-db.sql

4. Confirm access:

Enter the database password and wait for the export to complete.

5. Finally, simply access your files through SFTP

in /home/db-backups/ and download your database. :slight_smile:


  • RECOVER A BACKUP | IMPORT

1. First upload the database file to the server, via sftp/ftp.

For example, put in:

/home/db-backups/

Check:

$ cd /home/db-backups/ && ls

Confirm that the database has been loaded successfully.

eg: backup-my-db.sql

2. If the database appears listed, then run:

$ mysql -h localhost -u [user-name] -p [db-name] < backup-my-db.sql

Then enter the database password

PS:

The database that will receive the import, must be empty!