Hi Dude, this article is simple method how to backup and restore database mysql from command line cli. To backup and restore a MySQL database from the command line, we can use native command sql mysqldump and mysql commands, respectively. Lets do it.
Backup Mysql One Database from cli
Backup One Database
- Open a terminal and navigate to the directory where you want to save the backup file.
- Run the following command to create a backup of the database:
mysqldump -u username -p database_name > backup_file.sql- Replace
usernamewith the username you use to connect to the MySQL server anddatabase_namewith the name of the database you want to back up. The>operator redirects the output of themysqldumpcommand to a file namedbackup_file.sql. - Enter the password for the MySQL user when prompted.
- The backup file will be created in the current directory.
Restore One Database
Run the following command to restore the database.
mysql -u username -p database_name < backup_file.sqlBackup All Database
Execute this command create a backup of all databases:
mysqldump -u username -p --all-databases > backup_file.sqlRestore Mysql All Database
If we want to restore all database, please run the following command to restore.
mysql -u username -p < backup_file.sqlBackup Restore Mysql Include Store Procedure
This is additional, if we want to backup and restore mysql with include store procedure SPR.
mysqldump -u username -p --routines database_name > backup_file.sqlAnd to restore, run this command below.
mysql -u username -p --routines database_name < backup_file.sqlThat is simply article about how to backup and restore mysql from command line cli. Maybe usefull.