habibzain Just husband, father and enthusiastic men about System Administration. Love to write short article about it. Perhaps can help and be useful for others.

Mysql Backup and Restore from CLI

1 min read

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

  1. Open a terminal and navigate to the directory where you want to save the backup file.
  2. Run the following command to create a backup of the database:
mysqldump -u username -p database_name > backup_file.sql
  1. Replace username with the username you use to connect to the MySQL server and database_name with the name of the database you want to back up. The > operator redirects the output of the mysqldump command to a file named backup_file.sql.
  2. Enter the password for the MySQL user when prompted.
  3. 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.sql

Backup All Database

Execute this command create a backup of all databases:

mysqldump -u username -p --all-databases > backup_file.sql

Restore Mysql All Database

If we want to restore all database, please run the following command to restore.

mysql -u username -p < backup_file.sql

Backup 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.sql

And to restore, run this command below.

mysql -u username -p --routines database_name < backup_file.sql

That is simply article about how to backup and restore mysql from command line cli. Maybe usefull.

habibzain Just husband, father and enthusiastic men about System Administration. Love to write short article about it. Perhaps can help and be useful for others.

Easy Create Laravel Project with Composer

Requirement Laravel, a popular PHP framework, is renowned for its elegant syntax and robust features, making it a top choice for web developers. One...
habibzain
1 min read

Virtualbox Change Storage Size

Changing the storage size of a virtual machine in VirtualBox involves a few steps. Here’s a general guide. Backup your Virtual Machine (VM) Before...
habibzain
35 sec read

Easy Setup Logrotate Nginx Ubuntu

Log rotation is an important aspect of managing log files on a Linux system, including those generated by Nginx. Logrotate is a utility that...
habibzain
1 min read

Leave a Reply

Your email address will not be published. Required fields are marked *

Never miss good article from us, get weekly updates in your inbox