How to back up and restore a database in MySQL?

You can use the mysqldump command in MySQL to back up a database and the source command to restore it.

Backup database.

  1. Open the command line tool and input the following command to backup the database:
mysqldump -u username -p database_name > backup.sql

Using -u specifies the username, -p indicates that you need to input a password, database_name is the name of the database, and backup.sql is the name of the backup file.

  1. After entering the password, the backup file will be saved in the current directory.

Restore database.

  1. Open the command line tool and input the following command to restore the database:
mysql -u username -p database_name < backup.sql

The option -u specifies the username, -p indicates the need to input a password, database_name is the name of the database, and backup.sql is the name of the backup file.

  1. After entering the password, the database will be restored.
广告
Closing in 10 seconds
bannerAds