Detailed tutorial on backup and recovery of mysql data

Open a command prompt, log in mysql Open a command prompt and log in to mysqlquery the database

such as: backup database mybd, enter exit to exit
Going back to the original page, what we just did is just query which databases we havefrom this start Backup:
Code manipulationf disk It can be seen in the file has been successfully backed up the F drive!
mysqldump -u root -p mydb >F:\mydb_backup.sql
Analysis: mysqldump -u root -p (fixed format) + mydb (database name) **>** F:\mydb_backup.sql (storage path, mydb_backup.sql Is the name of the backup database, the name is arbitrary, the suffix should be sql).

Recovery:
Let's first query which tables are in mydb, suppose we accidentally delete the table user in the database

C:\Users\我爱学习>mysql -u root -p123
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 28
Server version: 8.0.16 MySQL Community Server - GPL

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mydb;
Database changed
mysql> show tables;
+----------------+
| Tables_in_mydb |
+----------------+
| users2         |
+----------------+
1 row in set (0.00 sec)

mysql> drop table if exists users2;
Query OK, 0 rows affected (0.03 sec)

mysql> show tables;
Empty set (0.00 sec)

Here you can see that mydb is empty and there are no tables.
Insert picture description hereNow we restore:
Two methods:
Method 1:
Input in the current database: source + backup database path The
Successful backupbackup is successful!
Insert picture description hereCheck the table, users2 is back.
Method 2:
Exit the current database and enter: mysql -u root -p database name <backup database path
Successful backupbackup successful!

Guess you like

Origin blog.csdn.net/weixin_44828960/article/details/108725215
Recommended