Use Mysqldump to export MySQL database
This tutorial will teach you how to mysqldump
export a MySQL database using the export utility.
We will see mysqldump
the syntax of using , its parameters and reasons to use it. We will also practice this utility by taking backup with/without data and exporting tables and databases.
For this guide, we use MySQL version 8.0.27. You can get the latest version (if available) from here.
mysqldump
Export/backup MySQL database using
In this day and age, DATA is everything. That is why database administrators keep our data safe and available 24/7; there are necessary and unexpected situations when they have to export data (data loss or data failure).
Keep in mind that the method of backup varies for different database platforms. Here, we will learn about the command line utilities for the MySQL database mysqldump
.
Reasons to use mysqldump
the utility
- The main reason is to backup the database when needed.
- You can export the database structure (database without data).
- It also allows you to backup single/many/all databases at once.
mysqldump
It also allows you to back up specific tables in specific databases.- It is very easy to use to export database with/without data.
- It has various parameters that we can adjust as needed to get the job done.
Using mysqldump
the utility's parameters
We will use some parameters for the commands used in this tutorial. -u [username]
_and_ -p [password]
are used to provide the username and password for connecting to the MySQL database. It is recommended that you enter the password later when asked, rather than -p
typing it after _(see the example given below).
Then [option]
appears where you can specify your requirements. For example, you want to use --no-data
the option to do a dataless backup.
After that, you need to [数据库名称]
. If you want to export a certain table from the database, you can [database name]
write it after [table name]
.
Next, you can >
export to a file using the (greater than) symbol or <
restore using the (less than) symbol as needed. You can learn about mysqldump
many other parameters of here.
Back up only the database structure
You may find that there are situations where you only want to export the database structure. In that case, you can use the command with the -d --no-data
option mysqldump
.
The following command will export person
the database structure.
mysqldump -u root -p --no-data person > E:\Backup\person_database_structure.sql
Backup single/multiple tables from a database
Sometimes, you need to export specific tables from a specific database. In this case, mysqldump
it allows you to back up single or multiple tables from that database.
You must write the table name after the database name to export a single table. You can write multiple table names after the database name to export multiple tables.
# export one table named customer from database named person
mysqldump -u root -p person customer > E:\Backup\customer_table_from_person.sql
# export two tables named customer and employee from database named person
mysqldump -u root -p person customer employee > E:\Backup\customer_employee_from_person.sql
Backup single/multiple/all databases
What if you focus on backing up all databases instead of just one? You can --all-database
use the option in the following ways mysqldump
.
mysqldump -u root -p --all-databases > E:\Backup\all_databases_backup.sql
If you only want to export one or more databases, you can write the database names after the option as follows --databases
, separated by a space.
mysqldump -u root -p --databases person courses > E:\Backup\person_courses_backup.sql
Use the following command to export a database.
mysqldump -u root -p person > E:\Backup\person_backup.sql
in conclusion
We learned about mysqldump
the command line utility in detail. We discussed its parameters and the reasons for using it. We also learned how to export single or multiple tables and databases with/without data using different parameters.
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
If ELSE in MySQL
Publish Date:2025/04/11 Views:85 Category:MySQL
-
In this tutorial, we aim to explore how to use IF ELSE the statement in MySQL. One of the key roles of a data analyst is to gather insights from the data and produce meaningful results. It can be done with the help of several data filtering
DATETIME vs. TIMESTAMP in MySQL
Publish Date:2025/04/11 Views:117 Category:MySQL
-
DATETIME and TIMESTAMP are two different data types that can be used to store values that must contain both a date and a time portion. In this article, we will understand how it is stored in the database and the memory required for ea
Execute multiple joins in one query in MYSQL
Publish Date:2025/04/11 Views:94 Category:MySQL
-
Have you ever wondered how to include multiple joins in one query in MySQL? You have come to the right place. Remember that joins allow us to access information from other tables. This information is included separately to avoid redundancy.
Joining 3 tables in MySQL
Publish Date:2025/04/11 Views:187 Category:MySQL
-
In this tutorial, we will learn how to join three tables in MySQL. Businesses and organizations may have to visualize three tables simultaneously based on certain matching columns common to all three tables. This operation is allowed in MyS
Use of UPDATE JOIN in MySQL
Publish Date:2025/04/11 Views:85 Category:MySQL
-
This tutorial will explain how to use the statement in MySQL database UPDATE JOIN . We generally use joins to iterate over the rows in a particular table which may or may not have similar rows in other tables. We can UPDATE use JOIN the cla
How to use the Row_Number() function in MySQL
Publish Date:2025/04/11 Views:142 Category:MySQL
-
In this tutorial, we will explain how to use the VALUES function in MySQL ROW_NUMBER() . This is a sorting method that assigns consecutive numbers within a partition starting from 1. It is important to note that no two rows within a partiti
Multiple primary keys in MySQL
Publish Date:2025/04/11 Views:66 Category:MySQL
-
In this tutorial, our goal is to explore the concept of multiple primary keys for a table in MySQL. Many times, businesses and organizations have to assign certain columns as primary keys. This primary key has multiple uses and reasons to b
Displaying foreign keys in MySQL
Publish Date:2025/04/11 Views:55 Category:MySQL
-
In this tutorial, we aim to explore how to display foreign keys for tables and columns in MySQL. The type of key that references a primary key, also known as the primary key of another table, is called a foreign key. Understanding the forei
Select first N rows in MySQL
Publish Date:2025/04/11 Views:85 Category:MySQL
-
Sometimes, you have to select first N rows of MySQL database according to your project requirements. n The value of varies according to the requirement; it can be TOP 1 row or TOP 30 rows. We will learn how to select top N rows using the cl