Home > Database > Mysql Tutorial > How to backup and restore MySQL database?

How to backup and restore MySQL database?

不言
Release: 2019-02-28 11:16:53
Original
3141 people have browsed it

MySQL is a database server that permanently stores data. If using MySQL Server, you need to create a database backup to recover from a crash. mysql provides a utility mysqldump for backup. In this article, we will introduce the archive formats concerned with backup databases in .sql format. Its various options will also be explained.

How to backup and restore MySQL database?

Options for creating a MySQL database backup

There are many methods for creating a database backup. For this example, we use the database name "mydb".

1. Full database backup in ordinary .sql file

 # mysqldump -u root -p mydb > mydb.sql
Copy after login

2. Full database backup in archived .sql.gz file

 # mysqldump -u root -p mydb |gzip> mydb.sql.gz
Copy after login

3. Back up a single table only

#mysqldump -u root -p mydb tbl_student > tbl_student.sql
Copy after login

4. Back up multiple databases

#mysqldump -u root -p --databases mydb1 mydb2 mydb3 > mydb1-mydb2-mydb3.sql
Copy after login

5. Back up all databases

 # mysqldump -u root -p--all-databases> all-db-backup.sql
Copy after login

6. Back up only the database structure (no data)

 # mysqldump -u root -p--no-datamydb > mydb.sql
Copy after login

7. Back up only the database data (no table structure)

 # mysqldump -u root -p--no-create-infomydb > mydb.sql
Copy after login

8. Back up MySQL database in XML format

#mysqldump -u root -p --xml mydb> mydb.xml
Copy after login

How to restore MySQL backup?

Restoring a database from backup is very simple. We use mysql command. For example, the following command restores all backups from mydb.sql to the mydb database.

#mysql -u root -p mydb <mydb.sql
Copy after login

This article has ended here. For more other exciting content, you can pay attention to the relevant column tutorials on the php Chinese website! ! !

The above is the detailed content of How to backup and restore MySQL database?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template