mysql-- database backup - using the mysqldump command to back up a database of some tables and a database of all the tables

Note: mysqldump command structure first need to find out to back up the table, and then generate a create statement in a text file,

 

           Then all records in the table, is converted into an insert statement. These statements create and insert statements are reducing use of.

 

           When you restore the database is to first create statement to use to build the table, insert statement to restore the data.

 

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

 

A, mysqldump command to back up a database of some of the tables ;

 

Syntax: mysqldump -u username -ppassword dbname table1 table2 ......> backupname.sql

 

dbname: indicates the database name;

 

table1 table2 ......: indicates the name of the table

 

backupname.sql: represents the path and file name of the backup;

                             .Sql file backup is usually, but not necessarily .sql files, .sql file gives the impression that the database file. It may be .txt files.

 

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

 

 

Backup before the data:

 

 

 

 

 

 

 

 

 

 

cmd to enter DOS, type the command, backup, and employee cr01 two tables:

Cr01 will see inside the database and employee table for backup, the backup to the desktop: C: \ Users \ del \ Desktop \, the backup file is named see.sql

mysqldump -u root -p123 see cr01 employee > C:\Users\del\Desktop\see.sql

 

 桌面多了一个see.sql文件,文件内容如下:

-- 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 */;

--
-- 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 `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 21:37:01

 

 

 上面这个文件里面没有创建数据库的语句。因为是还原到一个已有的数据库里。

 

 

 

 

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

 

 

 

 

 

二、备份某个数据库里面的所有表

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

-- 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 */;

--
-- 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 21:59:15

Guess you like

Origin www.cnblogs.com/xiaobaibailongma/p/12104644.html