备份时:(例如需要备份的数据库叫hell)
1.先关闭之前的数据库(exit,quit都可以)
mysql> quit;
Bye
2.用win+r,输入cmd,打开一个新的输入框,输入mysqldump -u root -p hell>hell.sql
C:\Users\Administrator>mysqldump -u root -p hell>hell.sql
Enter password: ********
3.再用mysqldump -u root -p hell,检查之前hell库中的内容
C:\Users\Administrator>mysqldump -u root -p hell
Enter password: ********
-- MySQL dump 10.13 Distrib 5.7.21, for Win32 (AMD64)
--
-- Host: localhost Database: hell
-- ------------------------------------------------------
-- Server version 5.7.21-log
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `wl`
--
DROP TABLE IF EXISTS `wl`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `wl` (
`name` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `wl`
--
LOCK TABLES `wl` WRITE;
/*!40000 ALTER TABLE `wl` DISABLE KEYS */;
INSERT INTO `wl` VALUES ('瀹濊礉');
/*!40000 ALTER TABLE `wl` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2019-02-27 14:10:21
4.进入mysql -u root -p,输入密码
C:\Users\Administrator>mysql -u root -p
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 37
Server version: 5.7.21-log MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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.
5.此时删除hell库(drop database hell;)
mysql> drop database hell;
Query OK, 1 row affected (0.18 sec)
恢复时:
1.创建hell库
create database hell;
Query OK, 1 row affected (0.01 sec)
2.quit退出
3.打开一个新的输入框,输入mysql -u root -p hell<hell.sql
4.恢复完成,输入mysql -u root -p,进入
5.检查
输入show databases;查看hell是否存在,
输入use hell;
再输入 show tables;看hell数据库下的表wl是否存在
再输入select * from wl;看wl表中的数据是否还在