MySQL数据导出工具 mysqldump

MySQL版本信息:

1[root@db02 data]# mysql --version 2mysql Ver 14.14 Distrib 5.6.36, for Linux (x86_64) using EditLine wrapper

选项:

-A , --all-databases

全库备份

-B , --databases

增加建库(create)及“use库”的语句

可以直接接多个库名,同时备份多个库

-B 库1 库2

-R , --routines

备份存储过程和函数数据

--triggers

备份触发器数据

--master-data={1|2}

告诉备份后时刻的binlog位置

2 注释

1 非注释,要执行(主从复制)对恢复没什么用

--single-transaction

对innodb引擎进行热备

-F, --flush-logs

刷新binlog日志

全备

[root@db02 ~]# mysqldump -uroot -p123 -A >/backup/full.sql

单库备份 使用-B的区别

1[root@db02 ~]# mysqldump -uroot -p123 test > ./test.sql 2Warning: Using a password on the command line interface can be insecure. 3 4[root@db02 ~]# mysqldump -uroot -p123 -B test > ./test_B.sql 5Warning: Using a password on the command line interface can be insecure. 6 7[root@db02 ~]# vimdiff test.sql test_B.sql

多库备份 --  -B 数据1 数据库2

1[root@db02 ~]# mysqldump -uroot -p123 -B test mysql > ./test_mysql.sql 2Warning: Using a password on the command line interface can be insecure.

多表备份 --  数据库名 表名1 表名2

1[root@db02 data]# mysqldump -uroot -p123 mysql user proc > ./mysql_user_proc.sql 2Warning: Using a password on the command line interface can be insecure.

--master-data=2

1[root@db02 data]# mysqldump -uroot -p123 --master-data=2 test > ./test.sql 2Warning: Using a password on the command line interface can be insecure. 3 4[root@db02 data]# vim ./test.sql 5 6-- CHANGE MASTER TO MASTER_LOG_FILE='mysql_bin.000002', MASTER_LOG_POS=262;

--single-transaction

1[root@db02 ~]# mysqldump -uroot -p123 --master-data=2 --single-transaction test > ./test2.sql 2Warning: Using a password on the command line interface can be insecure.

-F

1[root@db02 ~]# mysqldump -uroot -p123 --master-data=2 --single-transaction -R --triggers -B test -F > ./test3.sql 2Warning: Using a password on the command line interface can be insecure.

压缩备份

1[root@db02 ~]# mysqldump -uroot -p123 --master-data=2 --single-transaction -R --triggers -B test -F | gzip > ./test3.sql.gz 2Warning: Using a password on the command line interface can be insecure. 3 4[root@db02 ~]# ll ./test3.sql.gz 5-rw-r--r-- 1 root root 818 Apr 11 17:12 ./test3.sql.gz 6 7[root@db02 ~]# file ./test3.sql.gz 8./test3.sql.tar.gz: gzip compressed data, from Unix, last modified: Wed Apr 11 17:12:48 2018

解压

1[root@db02 ~]# mysqldump -uroot -p123 --master-data=2 --single-transaction -R --triggers -B test -F | gzip > ./test3.sql.gz 2Warning: Using a password on the command line interface can be insecure. 3 4[root@db02 ~]# gunzip test3.sql.gz 5或者 6[root@db02 ~]# gzip -d test3.sql.gz 7或者 8[root@db02 ~]# zcat test3.sql.gz > test3.sql

恢复

mysql> set sql_log_bin=0   # 恢复操作,不写入binlog日志中,因为写入也是无用的

mysql> source /root/test.sql

注:本博客仅供参考!

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )

MySQL数据导出工具 mysqldump - HelloWorld