MySQL Binlog信息查看
查看Binlog相关信息
##=====================================##
## 在MySQL内部查看binlog文件列表 ##
SHOW BINARY LOGS; ##=====================================##
##查看某个binglog文件中特定pos的操作
SHOW BINLOG EVENTS IN 'mysql-bin.000011' FROM 4742885 LIMIT 15; ##=====================================##
## 使用mysqlbinlog查看binlog ##
## 按时间过滤--start-datetime --stop-datetime,过滤时间格式为'2004-12-25 11:25:56'
## 按位置点过滤--start-position --stop-position,如果不能提供准确的pos值,则会报错
## 按照GTID过滤--include-gtids include-gtids
/export/servers/mysql/bin/mysqlbinlog -vv /export/data/mysql/data/mysql-bin.008735 /export/servers/mysql/bin/mysqlbinlog -vv /export/data/mysql/data/mysql-bin.008735 --start-datetime='2017-01-01 00:00:00' --stop-datetime='2017-01-02 00:00:00' /export/servers/mysql/bin/mysqlbinlog -vv /export/data/mysql/data/mysql-bin.008735 --start-position=194 --stop-position=201 /export/servers/mysql/bin/mysqlbinlog -vv /export/data/mysql/data/mysql-bin.008735 --include-gtids="2aa60248-d8cf-11e8-a5c5-fa1622b12630:22652-22659" ##=====================================##
## 查看binlog 文件大小和最后修改时间 ##
ll -h --time-style='+%Y-%m-%d %H:%M:%S' /export/data/mysql/data/mysql-bin*
解析Binlog获取操作频率:
/export/servers/mysql/bin/mysqlbinlog --no-defaults --base64-output=decode-rows -vvv mysql-bin.001282 \
| awk '/###/ {if($0~/UPDATE|INSERT|SELECT/)count[$2" "$NF]++}END{for(i in count) print i,"\t",count[i]}' \
| column -t | sort -k3nr
对解析出的SQL文件进行解析,计算每张表操作次数和每秒操作次数:
1、先使用mysqlbinlog解析文件:
/export/servers/mysql/bin/mysqlbinlog --no-defaults --base64-output=decode-rows -vvv mysql-bin.001282 >/tmp/001282.sql
2、修改下面python文件中main部分的sql文件地址,然后执行
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# =============================================================================
# FileName:
# Desc:
# Author:
# Email:
# HomePage:
# Version:
# LastChange:
# History:
# =============================================================================
import os def write_file(file_path, file_content):
file_handler = open(file_path, "w")
file_handler.write(file_content)
file_handler.close() def get_table_summary(dump_sql_path):
file_handler = open(dump_sql_path)
table_dict = dict()
for file_line in file_handler:
if file_line.find("Table_map: ") > 0:
start_index = file_line.index("Table_map:") + len("Table_map: ")
end_index = file_line.index("mapped to", start_index)
table_name = file_line[start_index:end_index].strip()
if table_name in table_dict.keys():
table_dict[table_name] += 1
else:
table_dict[table_name] = 1 result_list = list()
result_list.append("##=============按照表访问次数排序====================##")
sorted_table_dict = sorted(table_dict.items(), key=lambda x: int(x[1]), reverse=True)
for item in sorted_table_dict:
result_list.append("{0}======================{1}".format(item[0], item[1]))
result_list.append("##=============================================##")
result_file = os.path.join(os.path.dirname(__file__), "binlog_table_summary.txt")
write_file(result_file, "\n".join(result_list)) def get_binlog_time_summary(dump_sql_path):
file_handler = open(dump_sql_path)
datetime_dict = dict()
for file_line in file_handler:
if file_line.find("Table_map: ") > 0:
start_index = 1
end_index = file_line.index("server id", start_index)
current_time = file_line[start_index:end_index].strip()
if current_time in datetime_dict.keys():
datetime_dict[current_time] += 1
else:
datetime_dict[current_time] = 1
result_list = list()
result_list.append("##=============按照时间访问排序====================##")
sorted_time_dict = sorted(datetime_dict.items(), key=lambda x: x[0], reverse=True)
for item in sorted_time_dict:
result_list.append("{0}======================{1}".format(item[0], item[1]))
result_list.append("##=============================================##")
result_file = os.path.join(os.path.dirname(__file__), "binlog_time_summary.txt")
write_file(result_file, "\n".join(result_list)) if __name__ == '__main__':
sql_path = "/tmp/001282.sql"
print("正在解析数据文件{0},获取每表访问次数".format(sql_path))
get_table_summary(dump_sql_path=sql_path)
print("正在解析数据文件{0},获取每秒访问次数".format(sql_path))
get_binlog_time_summary(dump_sql_path=sql_path)
print("解析完成")
MySQL Binlog信息查看的更多相关文章
- mysql 分区信息查看
select partition_name part,partition_expression expr,partition_description descr,table_rows from INF ...
- 使用cygwin中的awk工具进行mysql binlog日志查看[利刃篇]
linux工具确实强悍,然而作为没有linux机器使用权以及开发没有使用linux进行的人,有时想用一些命令确实不方便,所以,才去试着用用cygwin,一款在windows平台上运行的类UNIX模拟环 ...
- mysql日志信息查看与设置mysql-bin
查看 sql查询记录 日志是否开启 SHOW GLOBAL VARIABLES LIKE '%general_log%' 二进制日志 是否开启 SHOW GLOBAL VARIABLES LIKE ...
- mysql binlog日志查看及解码
mysql bin log日志导出 mysqlbinlog mysql-bin.000005 > /home/17bin.log 需要添加参数(--base64-output=decode-r ...
- MySql Binlog 说明 & Canal 集成MySql的更新异常说明 & MySql Binlog 常用命令汇总
文章来源于本人的印象笔记,如出现格式问题可访问该链接查看原文 原创声明:作者:Arnold.zhao 博客园地址:https://www.cnblogs.com/zh94 目录 背景介绍 开启MySq ...
- MySQL binlog 自动清理脚本
# vim /data/scripts/delete_mysql_binlog.sh 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ...
- 关于MySQL相关的查看显示信息:
关于MySQL相关的查看显示信息: 数据库范围: 一.查看所有的数据库:(仅仅是看数据库数量与名字) mysql> show databases; 二.查看某个数据库的创建信息:(主要看数据库的 ...
- Window 下mysql binlog开启及查看,mysqlbinlog
查看是否开启了binlog: win+r => cmd => 连接mysql=>show variables like 'log_%'; mysql> show variabl ...
- CentOS6.8下MySQL数据库版本信息查看
方法1:使用mysql -v命令查看: [root@yeebian mysql]# mysql -V mysql Ver 14.14 Distrib 5.1.73, for redhat-linux- ...
随机推荐
- Linux使用定时器timerfd 和 eventfd接口实现进程线程通信
body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...
- java的类class 和对象object
java 语言的源代码是以类为单位存放在文件中,已public修饰的类名须和存放这个类的源文件名一样.而 一个源文件中只能有一个public的类,类名的首字母通常为大写. 使用public修饰的类可以 ...
- 2.5 C++类class和结构体struct区别
参考:http://www.weixueyuan.net/view/6337.html 总结: 在C++中,struct类似于class,在其中既可以定义数据成员,又可以定义成员函数. 在C++中,s ...
- 安装ubuntu不能引导win7
台式机安装了ubuntu导致进不了win7了,2系统在同一硬盘. win7引导需要bootmgr和boot文件夹中的文件,2个东东在winows引导分区根目录下. 我的笔记本安装windows系统分区 ...
- Final阶段贡献分配规则及实施
作业要求[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2479] 1.分配规则 final阶段开始,我们经过讨论,决定沿用alpha阶段 ...
- JavaWeb:c3p0配置问题-----java.sql.SQLException: Connections could not be acquired from the underlying database!
错误原因 c3p0的配置错误 错误显示 -classpath "D:\Program\Software\IntelliJIDEA\IntelliJ IDEA 2018.2.5\lib\ide ...
- outlook2016中如何设置两个账户都自动有各自默认签名
安装了Outlook2016以后,有些朋友不清楚,我们在发送邮件的时候,怎么添加邮件签名,其实在Outlook2016中添加邮件签名的方法也是比较简单的,这里小编介绍下在Outlook2016中设置添 ...
- express-session 产生的警告问题
调用express的express-session模块引发的警告问题 解决办法 调用的时候加上 resave:true, saveUninitialized:true eg: app.use(sess ...
- Pycharm出现Segmentation fault...(interrupted by signal 11: SIGSEGV)的解决方法
众所周知,用pycharm远程服务器debug代码已经成为学习深度学习相关代码的有力工具,但是最近创建了一个虚拟环境,进行debug的时候,莫名会出现下面这个错误,看的我都抽风了 bash: line ...
- cetos7最小化安装设置网络启动和更新yum源
1. 使用静态 IP 地址配置网络 你第一件要做的事情就是为你的 CentOS 服务器配置静态 IP 地址.路由以及 DNS.我们会使用 ip 命令代替 ifconfig 命令.当然,ifconfig ...