mysqldump,mysqlbinlog
发表于:2024-11-11 作者:千家信息网编辑
千家信息网最后更新 2024年11月11日,听课笔记:主要讲解内容:1.mysqldump2.mysqlcheck3.mysqlbinlog解析binlogmysqlbinlog -v --base64-output=decode-rows b
千家信息网最后更新 2024年11月11日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 /*!40100 SET @@SQL_MODE='' */
22 Query /*!40103 SET TIME_ZONE='+00:00' */
22 Query SHOW STATUS LIKE 'binlog_snapshot_%'
22 Query SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ #设置会话事务的隔离级别为可重复读
22 Query START TRANSACTION /*!40100 WITH CONSISTENT SNAPSHOT */ 开启一个一致性快照的事务
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 /*!40001 SQL_NO_CACHE */ * 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 /*!40100 SET @@SQL_MODE='' */
26 Query /*!40103 SET TIME_ZONE='+00:00' */
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 /*!32311 LOCAL */
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 /*!40001 SQL_NO_CACHE */ * 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
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
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
/*!100001 SET @@session.gtid_domain_id=0*//*!*/;
/*!100001 SET @@session.server_id=71493306*//*!*/;
/*!100001 SET @@session.gtid_seq_no=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 /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
从解析出来的binlog中可以看到:
gtid号,事务开始的logpossition467 ,和结束的logposition677 ,所做的修改为更改表test中id=99的改为test。最后隐式提交。
主要讲解内容:
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 /*!40100 SET @@SQL_MODE='' */
22 Query /*!40103 SET TIME_ZONE='+00:00' */
22 Query SHOW STATUS LIKE 'binlog_snapshot_%'
22 Query SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ #设置会话事务的隔离级别为可重复读
22 Query START TRANSACTION /*!40100 WITH CONSISTENT SNAPSHOT */ 开启一个一致性快照的事务
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 /*!40001 SQL_NO_CACHE */ * 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 /*!40100 SET @@SQL_MODE='' */
26 Query /*!40103 SET TIME_ZONE='+00:00' */
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 /*!32311 LOCAL */
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 /*!40001 SQL_NO_CACHE */ * 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
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
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
/*!100001 SET @@session.gtid_domain_id=0*//*!*/;
/*!100001 SET @@session.server_id=71493306*//*!*/;
/*!100001 SET @@session.gtid_seq_no=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 /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
从解析出来的binlog中可以看到:
gtid号,事务开始的logpossition467 ,和结束的logposition677 ,所做的修改为更改表test中id=99的改为test。最后隐式提交。
事务
一致
一致性
参数
普通
安全
代码
内容
快照
数据
数据库
日志
机制
笔记
级别
结构
过程
错误
作业
保证
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
英特尔12代 服务器
企业网络安全培训课程
攻击图的网络安全宣传周
网络安全评估价格
浙江常规网络技术咨询热线
地平线5服务器id为00
华为服务器怎么自己修复
软件开发sow文档
无限分层信息遗传网络技术
网络安全维护去哪个城市
免费好用的云服务器管理面板
微信是什么软件开发是
单词json文件转数据库
数据库中怎样附加文件
如何安全保管服务器上的文件
服务器间为啥没跨域问题
笔记本电脑服务器dns未响应
长春求职软件开发
人工智能软件开发企业
王者服务器一般是哪个区
python接口抓取数据库
工商银行哪个服务器好
vc 数据库查询到列表框
软件开发公司定级分岗制度
重庆网络安全技能大赛
天津浪潮国强软件开发有限公司
北京常规软件开发收购价格
咸宁市中小学网络安全教育
常见数据库的特点有哪些
尚仁科技互联网公司