MySQL study notes seven: data backup and recovery

1. Backup

The database exports SQL scripts and backs up the contents of the database, not the database!

  • mysqldump -u username -p password database name> path to the generated script file. For example: mysqldump -uroot -p123 mydb3>d:\mydb3.sql (same as mysql.exe and mysqld.exe, both in the bin directory)
  • Note, don’t put a semicolon, don’t log in to mysql, run directly under cmd
  • Note that the generated script file does not contain the create database statement

You can see the backed up data under the D drive! 

2. Recovery

2.1 The first way

mysql -u用户名 -p密码 数据库<脚本文件路径

The operation steps are as follows:

  • Delete the mydb3 database first, and then recreate the mydb3 database
  • mysql -uroot -p123 mydb3<d:\mydb3.sql
  • Note, don’t put a semicolon, don’t log in to mysql, run directly under cmd

2.2 The second way
 

登录mysql
source SQL脚本路径

The operation steps are as follows:

  • Delete the mydb3 database first, and then recreate the mydb3 database
  • Switch to mydb3 library
  • source d:\mydb3.sql

Guess you like

Origin blog.csdn.net/weixin_44679832/article/details/105276297