How to Backup and Restore MySQL Database Command Line in Windows

To backup and restore MySQL database using mysqldump command via Windows command line, simply use mysqldump -u username -p database_name > C:\backup\database_name.sql command on the command line to backup mysql database using mysldump, and to restore the MySQL database from mysqldump file, to use mysql -u [username] -p [database_name] < [dump_file.sql] command on the Windows command line or cmd.

How to Backup and Restore MySQL Database from mysqldump using Command Line in Windows

Here are two options for that via mysqldump command using command line or cmd in windows:

Option 1: Backup MySQL Database from mysqldump via Command Line Windows

Here are steps to take backup MySQL database using mysqldump command via command line or cmd in Windows:

Step 1: Open Command Line or CMD

To start Windows CMD or command line, you press “Windows key” + “R” on the keyboard, and type “cmd” in the Run dialog box, and press Enter:

Step 2: Navigate to MySQL Bin Directory

To create a backup of all MySQL databases, you will need to navigate to the MySQL bin directory from the command line or cmd, which you can do with cd C:\Program Files\MySQL\MySQL Server 8.0\bin command:

cd C:\Program Files\MySQL\MySQL Server 8.0\bin

Note that:- Replace the path with the location where you have installed MySQL into your server.

Step 3: Take a Backup of MySQL Database Using mysqldump via Command Line Windows

Now you can use mysqldump -u username -p database_name > C:\backup\database_name.sql command on the Windows command line to take a backup of MySQL database with the help of this command:

mysqldump -u username -p database_name > C:\backup\database_name.sql

Please replace the following in this command before use:

  • “username” with your MySQL username,
  • “database_name” with the name of the database you want to backup
  • “C:\backup\database_name.sql” with the path where you want to save the backup file

Once you run this command, the MySQL database backup will be saved in the same directory as the MySQL bin folder.

Here is the video guide on how to take backup of MySQL database using command prompt in windows:

Option 2: Restore MySQL Database Command Line Windows

Here are steps to restore MySQL database from mysqldump file using command line or cmd in windows:

Step 1: Open Command Line OR CMD

To start Windows CMD or command line, you press “Windows key” + “R” on the keyboard, and type “cmd” in the Run dialog box, and press Enter:

Step 2: Navigate to MySQL Bin Directory

Now, execute the following command on command prompt to navigate to the MySQL bin directory:

cd C:\Program Files\MySQL\MySQL Server 8.0\bin

Note that:- Replace the path with the location where you have installed MySQL into your server.

Step 3: Create the Database

If you do not have a database, type mysql -u username -p -e "CREATE DATABASE database_name;" command on cmd or command line to create new a database:

mysql -u username -p -e "CREATE DATABASE database_name;"

Step 4: Restore the MySQL Database from mysqldump File in Windows using Command Line

To restore MySQL database from mysqldump file, simply type the command mysql -u username -p database_name < backup_file.sql in the Windows command line, and press Enter, and it will be done quickly:

mysql -u username -p database_name < backup_file.sql

Please replace the following in this command before use:

  • “username” with your MySQL username
  • “database_name” with the name of the database you want to restore
  • “backup_file.sql” with the name of the backup file

Once you run this command, the MySQL database will be restored from the MySQL dump file.

Here is the video guide on How to Restore MySQL Database From Dump File using Command Line Windows:

Conclusion

Backing up and restoring MySQL databases from the command line in Windows is a simple and effective way to protect your data and ensure business continuity.

Recommended Windows Tutorials

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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