• mysql——数据库备份——使用mysqldump命令备份一个或者多个数据库


    mysqldump命令备份一个或者多个数据库

    语法格式:mysqldump -u username -ppassword --databases dbname1 dbname2…… > backupname.sql

    --databases:这个选项表示后面跟一个或者多个数据库。注意前面不是一个横杆,是两个小横杆。

    dbname:表示数据库名称;

    table1 table2……:表示表的名称

    backupname.sql:表示路径和备份的文件名称;

                                 通常备份为.sql文件,但是并非一定是.sql文件,.sql文件给人的感觉是数据库文件。也可以是.txt文件等。

    ============================================================================================

    数据库准备see,下面有3个表和数据

     

     

    =========================================================================================

    备份一个数据库,即:演示备份see数据库:

    mysqldump -u root -p123 --databases see > C:\Users\del\Desktop\s.sql

     ps:里面有创建数据库的语句

    -- MySQL dump 10.13  Distrib 5.5.15, for Win32 (x86)
    --
    -- Host: localhost    Database: see
    -- ------------------------------------------------------
    -- Server version    5.5.15
    
    /*!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 */;
    
    --
    -- Current Database: `see`
    --
    
    CREATE DATABASE /*!32312 IF NOT EXISTS*/ `see` /*!40100 DEFAULT CHARACTER SET latin1 */;
    
    USE `see`;
    
    --
    -- Table structure for table `cr01`
    --
    
    DROP TABLE IF EXISTS `cr01`;
    /*!40101 SET @saved_cs_client     = @@character_set_client */;
    /*!40101 SET character_set_client = utf8 */;
    CREATE TABLE `cr01` (
      `sx` int(50) DEFAULT NULL,
      `mz` varchar(50) DEFAULT NULL,
      `bz` varchar(50) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    /*!40101 SET character_set_client = @saved_cs_client */;
    
    --
    -- Dumping data for table `cr01`
    --
    
    LOCK TABLES `cr01` WRITE;
    /*!40000 ALTER TABLE `cr01` DISABLE KEYS */;
    INSERT INTO `cr01` VALUES (1,'sww','sww01'),(2,'aww','aww02'),(3,'qww','qww03'),(4,'eww','eww04'),(5,'rww','rww05'),(6,'yww','yww06'),(7,'uww','uww07');
    /*!40000 ALTER TABLE `cr01` ENABLE KEYS */;
    UNLOCK TABLES;
    
    --
    -- Table structure for table `department`
    --
    
    DROP TABLE IF EXISTS `department`;
    /*!40101 SET @saved_cs_client     = @@character_set_client */;
    /*!40101 SET character_set_client = utf8 */;
    CREATE TABLE `department` (
      `d_id` int(50) DEFAULT NULL,
      `d_name` varchar(50) DEFAULT NULL,
      `functione` varchar(50) DEFAULT NULL,
      `address` varchar(50) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    /*!40101 SET character_set_client = @saved_cs_client */;
    
    --
    -- Dumping data for table `department`
    --
    
    LOCK TABLES `department` WRITE;
    /*!40000 ALTER TABLE `department` DISABLE KEYS */;
    INSERT INTO `department` VALUES (1001,'keyanbu','yanfachanpin','3lou5hao'),(1002,'shengchanbu','shengchanchanp','5louyiceng'),(1003,'xiaoshoubu','cehuaxiaoshou','1louxiaoshoudating');
    /*!40000 ALTER TABLE `department` ENABLE KEYS */;
    UNLOCK TABLES;
    
    --
    -- Table structure for table `employee`
    --
    
    DROP TABLE IF EXISTS `employee`;
    /*!40101 SET @saved_cs_client     = @@character_set_client */;
    /*!40101 SET character_set_client = utf8 */;
    CREATE TABLE `employee` (
      `num` int(50) DEFAULT NULL,
      `d_id` int(50) DEFAULT NULL,
      `name` varchar(50) DEFAULT NULL,
      `age` int(50) DEFAULT NULL,
      `sex` varchar(50) DEFAULT NULL,
      `homeadd` varchar(50) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    /*!40101 SET character_set_client = @saved_cs_client */;
    
    --
    -- Dumping data for table `employee`
    --
    
    LOCK TABLES `employee` WRITE;
    /*!40000 ALTER TABLE `employee` DISABLE KEYS */;
    INSERT INTO `employee` VALUES (1,1001,'zhangsan',26,'nan','beijing'),(2,1001,'lisi',24,'nv','hunan'),(3,1002,'wangwu',25,'nan','jiangsu'),(4,1004,'aric',15,'nan','yingguo');
    /*!40000 ALTER TABLE `employee` 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-12-26 22:12:22

    ===============================================================

    备份多个数据库,即:演示备份see 和 test 数据库:

    mysqldump -u root -p123 --databases see test > C:\Users\del\Desktop\st.sql

    ps:里面有创建2个数据库的命令;

    -- MySQL dump 10.13  Distrib 5.5.15, for Win32 (x86)
    --
    -- Host: localhost    Database: see
    -- ------------------------------------------------------
    -- Server version    5.5.15
    
    /*!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 */;
    
    --
    -- Current Database: `see`
    --
    
    CREATE DATABASE /*!32312 IF NOT EXISTS*/ `see` /*!40100 DEFAULT CHARACTER SET latin1 */;
    
    USE `see`;
    
    --
    -- Table structure for table `cr01`
    --
    
    DROP TABLE IF EXISTS `cr01`;
    /*!40101 SET @saved_cs_client     = @@character_set_client */;
    /*!40101 SET character_set_client = utf8 */;
    CREATE TABLE `cr01` (
      `sx` int(50) DEFAULT NULL,
      `mz` varchar(50) DEFAULT NULL,
      `bz` varchar(50) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    /*!40101 SET character_set_client = @saved_cs_client */;
    
    --
    -- Dumping data for table `cr01`
    --
    
    LOCK TABLES `cr01` WRITE;
    /*!40000 ALTER TABLE `cr01` DISABLE KEYS */;
    INSERT INTO `cr01` VALUES (1,'sww','sww01'),(2,'aww','aww02'),(3,'qww','qww03'),(4,'eww','eww04'),(5,'rww','rww05'),(6,'yww','yww06'),(7,'uww','uww07');
    /*!40000 ALTER TABLE `cr01` ENABLE KEYS */;
    UNLOCK TABLES;
    
    --
    -- Table structure for table `department`
    --
    
    DROP TABLE IF EXISTS `department`;
    /*!40101 SET @saved_cs_client     = @@character_set_client */;
    /*!40101 SET character_set_client = utf8 */;
    CREATE TABLE `department` (
      `d_id` int(50) DEFAULT NULL,
      `d_name` varchar(50) DEFAULT NULL,
      `functione` varchar(50) DEFAULT NULL,
      `address` varchar(50) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    /*!40101 SET character_set_client = @saved_cs_client */;
    
    --
    -- Dumping data for table `department`
    --
    
    LOCK TABLES `department` WRITE;
    /*!40000 ALTER TABLE `department` DISABLE KEYS */;
    INSERT INTO `department` VALUES (1001,'keyanbu','yanfachanpin','3lou5hao'),(1002,'shengchanbu','shengchanchanp','5louyiceng'),(1003,'xiaoshoubu','cehuaxiaoshou','1louxiaoshoudating');
    /*!40000 ALTER TABLE `department` ENABLE KEYS */;
    UNLOCK TABLES;
    
    --
    -- Table structure for table `employee`
    --
    
    DROP TABLE IF EXISTS `employee`;
    /*!40101 SET @saved_cs_client     = @@character_set_client */;
    /*!40101 SET character_set_client = utf8 */;
    CREATE TABLE `employee` (
      `num` int(50) DEFAULT NULL,
      `d_id` int(50) DEFAULT NULL,
      `name` varchar(50) DEFAULT NULL,
      `age` int(50) DEFAULT NULL,
      `sex` varchar(50) DEFAULT NULL,
      `homeadd` varchar(50) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    /*!40101 SET character_set_client = @saved_cs_client */;
    
    --
    -- Dumping data for table `employee`
    --
    
    LOCK TABLES `employee` WRITE;
    /*!40000 ALTER TABLE `employee` DISABLE KEYS */;
    INSERT INTO `employee` VALUES (1,1001,'zhangsan',26,'nan','beijing'),(2,1001,'lisi',24,'nv','hunan'),(3,1002,'wangwu',25,'nan','jiangsu'),(4,1004,'aric',15,'nan','yingguo');
    /*!40000 ALTER TABLE `employee` ENABLE KEYS */;
    UNLOCK TABLES;
    
    --
    -- Current Database: `test`
    --
    
    CREATE DATABASE /*!32312 IF NOT EXISTS*/ `test` /*!40100 DEFAULT CHARACTER SET latin1 */;
    
    USE `test`;
    /*!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-12-26 22:17:46
  • 相关阅读:
    [PA2014]Muzeum
    [TJOI2015]概率论
    To Do List
    【洛谷4172】 [WC2006]水管局长(LCT)
    HNOI2019退役记
    hdu 2159 FATE
    USACO 2019 January Contest, Platinum 题解
    luogu4774 [NOI2018]屠龙勇士
    NOI 2019游记
    loj #3145. 「APIO 2019」桥梁
  • 原文地址:https://www.cnblogs.com/xiaobaibailongma/p/12104663.html
Copyright © 2020-2023  润新知