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!