How to Backup MySQL Database in Windows

Naila Saad Siddiqui Feb 15, 2024
How to Backup MySQL Database in Windows

This quick tutorial will discuss backing up the MySQL database and saving it as a script in a file.

When working with the databases, it is advised to take regular backups of your database. This is because there can be some problematic situations in your development that can cause precious data loss.

To compensate for the undesirable data loss, we should take regular backups of databases. This can be done using a utility program known as mysqldump.

Use mysqldump Utility to Backup MySQL Database in Windows

The mysqldump client software creates logical backups by generating a set of SQL statements that may be run to recreate the original database object definitions and table contents.

It backs up or transfers one or more MySQL databases to another SQL server. The mysqldump may also provide CSV, text or XML output.

The correct syntax of this command is:

mysqldump.exe [options]

To run this command, we first need to go to the directory to mysql/bin. This directory has the mysqldump utility.

We need to provide different options like username, password, port number, database name, and a resultant file where the backup script will be saved.

Suppose we have a database named testdb for which we need to create the backup file; then, we need to execute the following command.

mysqldump.exe --user=root --password= --host=localhost --port=3306 --result-file="backupfile.sql" --databases "testdb"

mysqldump in cmd

After this command, you can locate the backupfile.sql in the same folder.

backup file

This file contains a script to create the database and all its tables with their corresponding data.

file contents

Related Article - MySQL Backup