我的编程空间,编程开发者的网络收藏夹
学习永远不晚

mysqldump,mysqlbinlog

短信预约 -IT技能 免费直播动态提醒
省份

北京

  • 北京
  • 上海
  • 天津
  • 重庆
  • 河北
  • 山东
  • 辽宁
  • 黑龙江
  • 吉林
  • 甘肃
  • 青海
  • 河南
  • 江苏
  • 湖北
  • 湖南
  • 江西
  • 浙江
  • 广东
  • 云南
  • 福建
  • 海南
  • 山西
  • 四川
  • 陕西
  • 贵州
  • 安徽
  • 广西
  • 内蒙
  • 西藏
  • 新疆
  • 宁夏
  • 兵团
手机号立即预约

请填写图片验证码后获取短信验证码

看不清楚,换张图片

免费获取短信验证码

mysqldump,mysqlbinlog

 听课笔记:
主要讲解内容:
1.mysqldump
2.mysqlcheck
3.mysqlbinlog 
解析binlog
mysqlbinlog -v --base64-output=decode-rows binglogname >/dir/dir.txt 

mysql_upgrade (升级)
更新一下新版本的表结构
mysql_upgrade -S /tmp/mysql3306.sock
perror (错误代码)

数据库的安全
select user,password,host from mysql.user;


课后作业:

mysqldump 

1、描述mysqldump的工作机制(可以测试mysqldump过程,借助general_log分析)
mysqldump 的这2个参数 --single-transaction --master-data 


 time mysqldump -q --single-transaction --master-data  --opt -R  --triggers  uu test > test.sql

real    0m0.045s
user    0m0.010s
sys    0m0.007s

解析一下普通的日志general_log
[root@manager mysql]# cat manager.log 

160727 19:29:57       22 Connect    root@localhost as anonymous on 
           22 Query                
           22 Query    
           22 Query    SHOW STATUS LIKE 'binlog_snapshot_%'   
           22 Query    SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ   #设置会话事务的隔离级别为可重复读
           22 Query    START TRANSACTION      开启一个一致性快照的事务
           22 Query    SHOW STATUS LIKE 'binlog_snapshot_%'
           22 Query    SELECT BINLOG_GTID_POS('mysql3306-mysql-bin.000017', '1176')
           22 Query    UNLOCK TABLES                                                   #释放锁
           22 Query    set optimizer_switch='semijoin=off'
           22 Query    SELECT LOGFILE_GROUP_NAME, FILE_NAME, TOTAL_EXTENTS, INITIAL_SIZE, ENGINE, EXTRA FROM INFORMATION_SCHEMA.FILES WHERE FILE_TYPE = 'UNDO LOG' AND FILE_NAME IS NOT NULL AND LOGFILE_GROUP_NAME IN (SELECT DISTINCT LOGFILE_GROUP_NAME FROM INFORMATION_SCHEMA.FILES WHERE FILE_TYPE = 'DATAFILE' AND TABLESPACE_NAME IN (SELECT DISTINCT TABLESPACE_NAME FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA='uu' AND TABLE_NAME IN ('test'))) GROUP BY LOGFILE_GROUP_NAME, FILE_NAME, ENGINE ORDER BY LOGFILE_GROUP_NAME
           22 Query    SELECT DISTINCT TABLESPACE_NAME, FILE_NAME, LOGFILE_GROUP_NAME, EXTENT_SIZE, INITIAL_SIZE, ENGINE FROM INFORMATION_SCHEMA.FILES WHERE FILE_TYPE = 'DATAFILE' AND TABLESPACE_NAME IN (SELECT DISTINCT TABLESPACE_NAME FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA='uu' AND TABLE_NAME IN ('test')) ORDER BY TABLESPACE_NAME, LOGFILE_GROUP_NAME
           22 Query    set optimizer_switch=default
           22 Init DB    uu
           22 Query    SHOW TABLES LIKE 'test'
           22 Query    SAVEPOINT sp       设置表的一个保存点
           22 Query    show table status like 'test'
           22 Query    SET SQL_QUOTE_SHOW_CREATE=1
           22 Query    SET SESSION character_set_results = 'binary'
           22 Query    show create table `test`
           22 Query    SET SESSION character_set_results = 'utf8'
           22 Query    show fields from `test`
           22 Query    SELECT * FROM `test`
           22 Query    SET SESSION character_set_results = 'binary'
           22 Query    use `uu`
           22 Query    select @@collation_database
           22 Query    SHOW TRIGGERS LIKE 'test'
           22 Query    SET SESSION character_set_results = 'utf8'
           22 Query    ROLLBACK TO SAVEPOINT sp    回滚到保存点sp (保证事务的一致性)
           22 Query    RELEASE SAVEPOINT sp        释放保存点sp
           22 Query    use `uu`
           22 Query    select @@collation_database
           22 Query    SET SESSION character_set_results = 'binary'
           22 Query    SHOW FUNCTION STATUS WHERE Db = 'uu'
           22 Query    SHOW PROCEDURE STATUS WHERE Db = 'uu'
           22 Query    SET SESSION character_set_results = 'utf8'
           22 Quit    

不加参数sigle_transaction

ime mysqldump -q   --opt -R  --triggers  uu test > test.sql

real    0m0.040s
user    0m0.010s
sys    0m0.008s
cat manager.log 

160727 19:56:49       26 Connect    root@localhost as anonymous on 
           26 Query    
           26 Query    
           26 Query    set optimizer_switch='semijoin=off'
           26 Query    SELECT LOGFILE_GROUP_NAME, FILE_NAME, TOTAL_EXTENTS, INITIAL_SIZE, ENGINE, EXTRA FROM INFORMATION_SCHEMA.FILES WHERE FILE_TYPE = 'UNDO LOG' AND FILE_NAME IS NOT NULL AND LOGFILE_GROUP_NAME IN (SELECT DISTINCT LOGFILE_GROUP_NAME FROM INFORMATION_SCHEMA.FILES WHERE FILE_TYPE = 'DATAFILE' AND TABLESPACE_NAME IN (SELECT DISTINCT TABLESPACE_NAME FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA='uu' AND TABLE_NAME IN ('test'))) GROUP BY LOGFILE_GROUP_NAME, FILE_NAME, ENGINE ORDER BY LOGFILE_GROUP_NAME
           26 Query    SELECT DISTINCT TABLESPACE_NAME, FILE_NAME, LOGFILE_GROUP_NAME, EXTENT_SIZE, INITIAL_SIZE, ENGINE FROM INFORMATION_SCHEMA.FILES WHERE FILE_TYPE = 'DATAFILE' AND TABLESPACE_NAME IN (SELECT DISTINCT TABLESPACE_NAME FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA='uu' AND TABLE_NAME IN ('test')) ORDER BY TABLESPACE_NAME, LOGFILE_GROUP_NAME
           26 Query    set optimizer_switch=default
           26 Init DB    uu
           26 Query    SHOW TABLES LIKE 'test'
           26 Query    LOCK TABLES `test` READ
           26 Query    show table status like 'test'
           26 Query    SET SQL_QUOTE_SHOW_CREATE=1
           26 Query    SET SESSION character_set_results = 'binary'
           26 Query    show create table `test`
           26 Query    SET SESSION character_set_results = 'utf8'
           26 Query    show fields from `test`
           26 Query    SELECT * FROM `test`
           26 Query    SET SESSION character_set_results = 'binary'
           26 Query    use `uu`
           26 Query    select @@collation_database
           26 Query    SHOW TRIGGERS LIKE 'test'
           26 Query    SET SESSION character_set_results = 'utf8'
           26 Query    LOCK TABLES mysql.proc READ
           26 Query    use `uu`
           26 Query    select @@collation_database
           26 Query    SET SESSION character_set_results = 'binary'
           26 Query    SHOW FUNCTION STATUS WHERE Db = 'uu'
           26 Query    SHOW PROCEDURE STATUS WHERE Db = 'uu'
           26 Query    SET SESSION character_set_results = 'utf8'
           26 Query    UNLOCK TABLES
           26 Query    UNLOCK TABLES
           26 Quit    


通过比较可以看出:不加single_transaction最后才释放锁,没有rollback,没有savepoing
2、mysqlbinlog解析一个事务
[root@manager data]# mysqlbinlog -v --base64-output=decode-rows mysql3306-mysql-bin.000020 
;
;
;
DELIMITER ;
# at 4
#160727 20:32:11 server id 71493306  end_log_pos 248     Start: binlog v 4, server v 10.0.22-MariaDB-log created 160727 20:32:11
# at 248
#160727 20:32:11 server id 71493306  end_log_pos 287     Gtid list [0-71493306-283]
# at 287
#160727 20:32:11 server id 71493306  end_log_pos 336     Binlog checkpoint mysql3306-mysql-bin.000019
# at 336
#160727 20:32:11 server id 71493306  end_log_pos 385     Binlog checkpoint mysql3306-mysql-bin.000020
# at 385
#160727 23:03:03 server id 71493306  end_log_pos 423     GTID 0-71493306-284
;
;
;
BEGIN
;
# at 423
# at 467
#160727 23:03:03 server id 71493306  end_log_pos 467     Table_map: `uu`.`test` mapped to number 76
#160727 23:03:03 server id 71493306  end_log_pos 677     Update_rows: table id 76 flags: STMT_END_F
### UPDATE `uu`.`test`
### WHERE
###   @1='uu'
###   @2=99
### SET
###   @1='test'
###   @2=99

# at 677
#160727 23:03:03 server id 71493306  end_log_pos 704     Xid = 460
COMMIT;

# End of log file
ROLLBACK ;
;
;


从解析出来的binlog中可以看到:
gtid号,事务开始的logpossition467 ,和结束的logposition677 ,所做的修改为更改表test中id=99的改为test。最后隐式提交。

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

mysqldump,mysqlbinlog

下载Word文档到电脑,方便收藏和打印~

下载Word文档

猜你喜欢

mysqlbinlog 工具用法

/etc/my.cnf的[mysqld]下添加或修改 log-bin=mysql-bin   基本用法:mysqlbinlog  binlog日志       --start-position=   初始位置     --stop-position=  结束位
mysqlbinlog 工具用法
2016-09-11

mysqlbinlog增量恢复

目录前言1.mysql的binlog日志是什么2.mysql的binlog日志的作用3.mysql的binlog日志功能如何开启4.mysqlbinlog工具解析binlog日志4.1.解析指定库的binlog日志4.2.按照位置截取binlog内容4.3.按
mysqlbinlog增量恢复
2014-11-02

mysqldump 备份

mysqldump -h192.168.1.100 -P3306 -udump -p --database test | gzip > /data/backup/test.sql.gz2.2 备份同个库多个表mysqldump -h192.168.1.100
mysqldump 备份
2016-12-30

mysqlbinlog: [ERROR] unknown variable ‘default-character-set=utf8‘

在使用mysqlbinlog 查看binlog时 发现 报如下错误 > ../bin/mysqlbinlog mysql-bin.000003 >./out.sqlmysqlbinlog: [ERROR] unknown variable
2023-08-16
2024-04-02

一文搞定MySQLbinlog/redolog/undolog区别

这篇文章主要介绍了一文搞定MySQLbinlog/redolog/undolog区别,作为开发,我们重点需要关注的是二进制日志(binlog)和事务日志(包括redolog和undolog),本文接下来会详细介绍这三种日志,需要的朋友可以参考下
2023-05-16

编程热搜

目录