mysql dba系统学习(16)mysql的mysqldump备份

简介:

                mysql数据库的备份恢复

mysqldump备份数据库

 -B, --databases     Dump several databases. Note the difference in usage; in

                     this case no tables are given. All name arguments are

                     regarded as database names. 'USE db_name;' will be

                     included in the output.


 -e, --extended-insert

                     Use multiple-row INSERT syntax that include several

                     VALUES lists.  多行插入数据


    为了保证数据的一致性,我们要把表锁起来在dump

-F, --flush-logs    Flush logs file in server before starting dump. Note that

                     if you dump many databases at once (using the option

                     --databases= or --all-databases), the logs will be

                     flushed for each database dumped. The exception is when

                     using --lock-all-tables or --master-data: in this case

                     the logs will be flushed only once, corresponding to the

                     moment all tables are locked. So if you want your dump

                     and the log flush to happen at the same exact moment you

                     should use --lock-all-tables or --master-data with

                     --flush-logs.

               

-x, --lock-all-tables

                     Locks all tables across all databases. This is achieved

                     by taking a global read lock for the duration of the

                     whole dump. Automatically turns --single-transaction and

                     --lock-tables off.

 -l, --lock-tables   Lock all tables for read.



--master-data[=#]   This causes the binary log position and filename to be

                     appended to the output. If equal to 1, will print it as a

                     CHANGE MASTER command; if equal to 2, that command will

                     be prefixed with a comment symbol. This option will turn

                     --lock-all-tables on, unless --single-transaction is

                     specified too (in which case a global read lock is only

                     taken a short time at the beginning of the dump; don't

                     forget to read about --single-transaction below). In all

                     cases, any action on logs will happen at the exact moment

                     of the dump. Option automatically turns --lock-tables

                     off.


-t, --no-create-info

                     Don't write table creation info.

 -d, --no-data       No row information.

 -N, --no-set-names  Suppress the SET NAMES statement

--opt               Same as --add-drop-table, --add-locks, --create-options,

                     --quick, --extended-insert, --lock-tables, --set-charset,

                     and --disable-keys. Enabled by default, disable with

                     --skip-opt.


 -q, --quick         Don't buffer query, dump directly to stdout.   不缓存



 -R, --routines      Dump stored routines (functions and procedures).



 --single-transaction

                     Creates a consistent snapshot by dumping all tables in a

                     single transaction. Works ONLY for tables stored in

                     storage engines which support multiversioning (currently

                     only InnoDB does); the dump is NOT guaranteed to be

                     consistent for other storage engines. While a

                     --single-transaction dump is in process, to ensure a

                     valid dump file (correct table contents and binary log

                     position), no other connection should use the following

                     statements: ALTER TABLE, DROP TABLE, RENAME TABLE,

                     TRUNCATE TABLE, as consistent snapshot is not isolated

                     from them. Option automatically turns off --lock-tables.


 --dump-date         Put a dump date to the end of the output.


--skip-opt          Disable --opt. Disables --add-drop-table, --add-locks,

                     --create-options, --quick, --extended-insert,

                     --lock-tables, --set-charset, and --disable-keys.

实践之非事务性一直备份(备份期间数据库不可写)

mysql> use  test

mysql> create table tt(id int,name varchar(12));

Query OK, 0 rows affected (0.11 sec)

mysql> insert into tt values(1,'zz');

Query OK, 1 row affected (0.01 sec)

mysql> insert into tt values(2,'yy');

Query OK, 1 row affected (0.00 sec)


[root@test4 Desktop]# mysqldump  --databases test  --skip-opt --quick --extended-insert=false --lock-all-tables --master-data=2  -u root -p123456 >  /tmp/test.sql

  这就是dump的结果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
[root@test4 Desktop]# cat /tmp/test.sql
-- MySQL dump  10.13   Distrib  5.1 . 70 for  unknown-linux-gnu (x86_64)
--
-- Host: localhost    Database: test
-- ------------------------------------------------------
-- Server version    5.1 . 70 -log
/*!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 */ ;
--
-- Position to start replication or point- in -time recovery from
--
-- CHANGE MASTER TO MASTER_LOG_FILE= 'mysqlbin.000166' , MASTER_LOG_POS= 798 ;
--
-- Current Database: `test`
--
CREATE DATABASE  /*!32312 IF NOT EXISTS*/  `test`  /*!40100 DEFAULT CHARACTER SET utf8 */ ;
USE `test`;
--
-- Table structure  for  table `tt`
--
/*!40101 SET @saved_cs_client     = @@character_set_client */ ;
/*!40101 SET character_set_client = utf8 */ ;
CREATE TABLE `tt` (
   `id`  int ( 11 ) DEFAULT NULL,
   `name`  var char( 12 ) DEFAULT NULL
);
/*!40101 SET character_set_client = @saved_cs_client */ ;
--
-- Dumping data  for  table `tt`
--
INSERT INTO `tt` VALUES ( 1 , 'zz' );
INSERT INTO `tt` VALUES ( 2 , 'yy' );
/*!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 */ ;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */ ;
-- Dump completed on  2013 - 09 - 05  20 : 15 : 38

     由于我们dump的时候用了master-data参数,这个时候记录了日志位置和日志文件名

-- CHANGE MASTER TO MASTER_LOG_FILE='mysqlbin.000166', MASTER_LOG_POS=798;

实践之事务性一直备份(备份期间数据库可写)

mysql> use  test

mysql> create table tt(id int,name varchar(12)) engine=innodb ;

Query OK, 0 rows affected (0.11 sec)

mysql> insert into tt values(1,'zz');

Query OK, 1 row affected (0.01 sec)

mysql> insert into tt values(2,'yy');

Query OK, 1 row affected (0.00 sec)


[root@test4 Desktop]# mysqldump  --databases test  --skip-opt --quick --extended-insert=false  --single-transaction   --master-data=2  -u root -p123456 >  /tmp/test.sql




本文转自陈仲阳0 51CTO博客,原文链接:http://blog.51cto.com/wolfword/1289596
相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。   相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情: https://www.aliyun.com/product/rds/mysql 
相关文章
|
9月前
|
NoSQL 算法 Redis
【Docker】(3)学习Docker中 镜像与容器数据卷、映射关系!手把手带你安装 MySql主从同步 和 Redis三主三从集群!并且进行主从切换与扩容操作,还有分析 哈希分区 等知识点!
Union文件系统(UnionFS)是一种**分层、轻量级并且高性能的文件系统**,它支持对文件系统的修改作为一次提交来一层层的叠加,同时可以将不同目录挂载到同一个虚拟文件系统下(unite several directories into a single virtual filesystem) Union 文件系统是 Docker 镜像的基础。 镜像可以通过分层来进行继承,基于基础镜像(没有父镜像),可以制作各种具体的应用镜像。
930 6
|
10月前
|
SQL 关系型数据库 MySQL
Mysql基础学习day01
本课程为MySQL基础学习第一天内容,涵盖MySQL概述、安装、SQL简介及其分类(DDL、DML、DQL、DCL)、数据库操作(查询、创建、使用、删除)及表操作(创建、约束、数据类型)。适合初学者入门学习数据库基本概念和操作方法。
315 6
|
10月前
|
关系型数据库 MySQL 数据管理
Mysql基础学习day03-作业
本内容包含数据库建表语句及多表查询示例,涵盖内连接、外连接、子查询及聚合统计,适用于员工与部门数据管理场景。
187 1
|
10月前
|
SQL 关系型数据库 MySQL
Mysql基础学习day02-作业
本教程介绍了数据库表的创建与管理操作,包括创建员工表、插入测试数据、删除记录、更新数据以及多种查询操作,涵盖了SQL语句的基本使用方法,适合初学者学习数据库操作基础。
204 0
|
10月前
|
SQL 关系型数据库 MySQL
Mysql基础学习day03
本课程为MySQL基础学习第三天内容,主要讲解多表关系与多表查询。内容涵盖物理外键与逻辑外键的区别、一对多、一对一及多对多关系的实现方式,以及内连接、外连接、子查询等多表查询方法,并通过具体案例演示SQL语句的编写与应用。
278 0
|
10月前
|
SQL 关系型数据库 MySQL
Mysql基础学习day01-作业
本教程包含三个数据库表的创建练习:学生表(student)要求具备主键、自增长、非空、默认值及唯一约束;课程表(course)定义主键、非空唯一字段及数值精度限制;员工表(employee)包含自增主键、非空字段、默认值、唯一电话号及日期时间类型字段。每个表的结构设计均附有详细SQL代码示例。
185 0
|
10月前
|
SQL 关系型数据库 MySQL
Mysql基础学习day02
本课程为MySQL基础学习第二天内容,涵盖数据定义语言(DDL)的表查询、修改与删除操作,以及数据操作语言(DML)的增删改查功能。通过具体SQL语句与实例演示,帮助学习者掌握MySQL表结构操作及数据管理技巧。
249 0
|
10月前
|
缓存 关系型数据库 BI
使用MYSQL Report分析数据库性能(下)
使用MYSQL Report分析数据库性能
599 158
|
10月前
|
关系型数据库 MySQL 数据库
自建数据库如何迁移至RDS MySQL实例
数据库迁移是一项复杂且耗时的工程,需考虑数据安全、完整性及业务中断影响。使用阿里云数据传输服务DTS,可快速、平滑完成迁移任务,将应用停机时间降至分钟级。您还可通过全量备份自建数据库并恢复至RDS MySQL实例,实现间接迁移上云。
|
10月前
|
关系型数据库 MySQL 数据库
阿里云数据库RDS费用价格:MySQL、SQL Server、PostgreSQL和MariaDB引擎收费标准
阿里云RDS数据库支持MySQL、SQL Server、PostgreSQL、MariaDB,多种引擎优惠上线!MySQL倚天版88元/年,SQL Server 2核4G仅299元/年,PostgreSQL 227元/年起。高可用、可弹性伸缩,安全稳定。详情见官网活动页。
1598 152

推荐镜像

更多