mysql uses commands to export and import data (data backup, recovery)

1. Use mysql for data backup and recovery, the Navicat for MySQL client tool we use most:

data backup:

DataBase (selected data)-> Dump SQL File-> Structure + Data-> fill in the name of the dumped sql file-> select the dump address-> click save.
Insert picture description here
Insert picture description here

Data Recovery:

Create a new database-> select data-> Execute SQL File-> select the sql file to be executed

Insert picture description here
Insert picture description here
Insert picture description here

2. It is really convenient and intuitive to use Navicat for MySQL client tool to import and export data. But in the production environment, when the amount of data is large, it will be unsafe and time-consuming (and when I import the data, I have been importing data for several hours, and the progress is 120%). In this case, another import and export the way.

3. Use commands to import and export sql files

3.1 Export mysql file

Enter the bin directory of mysql and execute

./mysqldump -uroot -p testDB > /Users/diguoliang/Documents/jrong/db/testDB.sql

**

Note: I am using a mac, and the address of my export file is /Users/diguoliang/Documents/jrong/db/testDB.sql

**
Insert picture description here
Exporting in this way is obviously faster than exporting with client tools.

3.2 Import mysql file

If you import another machine, you need to create a new database first.
Enter the bin directory of
Insert picture description here
mysql After entering the bin directory of mysql, execute

./mysql -u root -p

Insert picture description here
Switch to the testDB database and import the mysql file

source /Users/diguoliang/Documents/jrong/db/testDB.sql

Insert picture description here

Guess you like

Origin blog.csdn.net/ytangdigl/article/details/106715037