Home >Backend Development >PHP Tutorial >How to backup and import database in mysql

How to backup and import database in mysql

小云云
小云云Original
2018-03-03 13:07:552462browse


This article mainly shares with you how to back up and import the MySQL database. I hope it can help you.

Back up all databases
Execute from the system command line: mysqldump -uusername -ppassword --all-databases > all.sql

Back up a single database
Execute from the system command line: mysqldump -uusername -ppassword --databases db1 db2 > db.sql
Export db1 and db2 to a db.sql file.

Import database
1. Execute from the system command line: mysql -uusername -ppassword db1 < db1.sql
In this case, the db1 database must be built in advance.
2. Or execute under the mysql command line: source db1.sql
In this method, there is no need to create a database in advance, and the database will be created automatically.

Related recommendations:

Several methods of mysql database backup

Introduction to the use of MySQL database backup tool Mydumper

Detailed explanation of import and export of MySQL database

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

Statement:
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