文章详情

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

请输入下面的图形验证码

提交验证

短信预约提醒成功

mysqldump,mysqlbinlog

2024-04-02 19:55

关注
 听课笔记:
主要讲解内容:
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

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-数据库
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯