Open a command prompt, log in mysql query the database
such as: backup database mybd, enter exit to exit
from this start Backup:
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.
Now we restore:
Two methods:
Method 1:
Input in the current database: source + backup database path The
backup is successful!
Check the table, users2 is back.
Method 2:
Exit the current database and enter: mysql -u root -p database name <backup database path
backup successful!