mysqlbinlog使用记录

首先要确认mysql启用了binlog功能。一般默认启用。

mysql> select @@log_bin;
+-----------+
| @@log_bin |
+-----------+
|         1 |
+-----------+

然后确认binlog目录

mysql> select @@log_bin_basename;
+----------------------------+
| @@log_bin_basename         |
+----------------------------+
| /data/mysql/data/mysql-bin |
+----------------------------+
1 row in set (0.20 sec)

再确认binlog格式,一般都是ROW

mysql> select @@binlog_format;
+-----------------+
| @@binlog_format |
+-----------------+
| ROW             |
+-----------------+
1 row in set (0.24 sec)

查看下当前的binlog文件。最后一个。

mysql> show master status;
+------------------+-----------+--------------+------------------+------------------------------------------------+
| File             | Position  | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set                              |
+------------------+-----------+--------------+------------------+------------------------------------------------+
| mysql-bin.000162 | 508947599 |              |                  | 8c6a1022-2488-11ee-823a-fa163e4f0fbf:1-1706820 |
+------------------+-----------+--------------+------------------+------------------------------------------------+
1 row in set (0.19 sec)

查看binlog清单。


mysql> show master logs;
+------------------+------------+-----------+
| Log_name         | File_size  | Encrypted |
+------------------+------------+-----------+
| mysql-bin.000097 | 1267374431 | No        |
| mysql-bin.000098 | 1078842954 | No        |
| mysql-bin.000099 | 1076402277 | No        |
| mysql-bin.000100 | 1074662461 | No        |
| mysql-bin.000101 | 1129645727 | No        |
| mysql-bin.000102 | 1073854117 | No        |
| mysql-bin.000103 | 1076120021 | No        |
| mysql-bin.000104 | 1163004975 | No        |
| mysql-bin.000105 | 1080999999 | No        |
| mysql-bin.000106 | 1123681007 | No        |
| mysql-bin.000107 | 1096492121 | No        |
| mysql-bin.000108 | 1080796650 | No        |
| mysql-bin.000109 | 1074606514 | No        |
| mysql-bin.000110 | 1094934164 | No        |
| mysql-bin.000111 | 1075325447 | No        |
| mysql-bin.000112 | 1204392658 | No        |
| mysql-bin.000113 | 1180372937 | No        |
| mysql-bin.000114 | 1196526678 | No        |
| mysql-bin.000115 | 1238177050 | No        |
| mysql-bin.000116 | 1074988755 | No        |
| mysql-bin.000117 | 1091344404 | No        |
| mysql-bin.000118 | 1076183240 | No        |
| mysql-bin.000119 | 1081950716 | No        |
| mysql-bin.000120 | 1109171293 | No        |
| mysql-bin.000121 | 1101011874 | No        |
| mysql-bin.000122 | 1218723442 | No        |
| mysql-bin.000123 | 1183060961 | No        |
| mysql-bin.000124 | 1106412574 | No        |
| mysql-bin.000125 | 1250171532 | No        |
| mysql-bin.000126 | 1078337881 | No        |
| mysql-bin.000127 | 1076340326 | No        |
| mysql-bin.000128 | 1073886411 | No        |
| mysql-bin.000129 | 1073771450 | No        |
| mysql-bin.000130 | 1073763024 | No        |
| mysql-bin.000131 | 1073754658 | No        |
| mysql-bin.000132 | 1073765124 | No        |
| mysql-bin.000133 | 1073758960 | No        |
| mysql-bin.000134 | 1167060782 | No        |
| mysql-bin.000135 | 1190829992 | No        |
| mysql-bin.000136 | 1096377082 | No        |
| mysql-bin.000137 | 1074835535 | No        |
| mysql-bin.000138 | 1097946487 | No        |
| mysql-bin.000139 | 1079454725 | No        |
| mysql-bin.000140 | 1073757655 | No        |
| mysql-bin.000141 | 1187881785 | No        |
| mysql-bin.000142 | 1096423858 | No        |
| mysql-bin.000143 | 1233191324 | No        |
| mysql-bin.000144 | 1080399415 | No        |
| mysql-bin.000145 | 1207148115 | No        |
| mysql-bin.000146 | 1211077714 | No        |
| mysql-bin.000147 | 1155530016 | No        |
| mysql-bin.000148 | 1141697366 | No        |
| mysql-bin.000149 | 1104053983 | No        |
| mysql-bin.000150 | 1181112005 | No        |
| mysql-bin.000151 | 1136589759 | No        |
| mysql-bin.000152 | 1077718940 | No        |
| mysql-bin.000153 | 1148381060 | No        |
| mysql-bin.000154 | 1185805639 | No        |
| mysql-bin.000155 | 1073741887 | No        |
| mysql-bin.000156 | 1104320103 | No        |
| mysql-bin.000157 | 1088572221 | No        |
| mysql-bin.000158 | 1076297985 | No        |
| mysql-bin.000159 | 1232823373 | No        |
| mysql-bin.000160 | 1213815833 | No        |
| mysql-bin.000161 | 1122061331 | No        |
| mysql-bin.000162 |  510032311 | No        |
+------------------+------------+-----------+

确认下binlog的文件

[iwhalecloud@apaas-mid1 data]$ lsapaas-mid1.log                  app_5195062153216_default_dev   app_d_1004304311066894336_dev   app_d_1010718326218174464_dev   app_d_1011464263104589824_dev   app_d_1016624577895215104_dev   app_d_1027753803562999808_dev   ca.pem               mysql-bin.000107   mysql-bin.000133   mysql-bin.000159app_0171769606782976_test_dev   app_587242401792_default_test   app_d_1004305219343425536_dev   app_d_1010790433914744832_dev   app_d_1011468334553231360_dev   app_d_1016630849134669824_dev   app_d_1027834867983568896_dev   client-cert.pem      mysql-bin.000108   mysql-bin.000134   mysql-bin.000160app_039531520_testappdemo_dev   app_618118144_zerocode_db_dev   app_d_1004305335215267840_dev   app_d_1010810408964583424_dev   app_d_1011475911693430784_dev   app_d_1016874600214048768_dev   app_d_1031846359492018176_dev   client-key.pem       mysql-bin.000109   mysql-bin.000135   mysql-bin.000161app_1154719241531392_utf8_dev   app_624027447296_default_test   app_d_1004305483873984512_dev   app_d_1010817221210533888_dev   app_d_1011512375550537728_dev   app_d_1017310111265206272_dev   app_d_1032242791453638656_dev   fastflow             mysql-bin.000110   mysql-bin.000136   mysql-bin.000162app_1189251336433664_jdxt_dev   app_6488617971712_shucun_test   app_d_1004326979078004736_dev   app_d_1010825204518744064_dev   app_d_1011538998677073920_dev   app_d_1018337333302321152_dev   app_d_1033622580274925568_dev  '#ib_16384_0.dblwr'   mysql-bin.000111   mysql-bin.000137   mysql.ibdapp_127492251648_default_test   app_659885162496_default_test   app_d_1005737741596581888_dev   app_d_1010832101951008768_dev   app_d_1011575392178925568_dev   app_d_1018338118778019840_dev   app_d_1033625372782837760_dev  '#ib_16384_1.dblwr'   mysql-bin.000112   mysql-bin.000138   mysql_upgrade_infoapp_138032611328_default_test   app_666318913536_default_test   app_d_1005738777421897728_dev   app_d_1010907921470058496_dev   app_d_1011575553651240960_dev   app_d_1018340928600989696_dev   app_d_1033983426992881664_dev   ib_buffer_pool       mysql-bin.000113   mysql-bin.000139   performance_schemaapp_174031101952_default_test   app_6845819412480_default_dev   app_d_1005739158608633856_dev   app_d_1010908254564904960_dev   app_d_1011827666318913536_dev   app_d_1018412911153754112_dev   app_d_1034827970723319808_dev   ibdata1              mysql-bin.000114   mysql-bin.000140   private_key.pemapp_1945102188544_default_dev   app_709634650112_default_test   app_d_1005739257745203200_dev   app_d_1010908346898313216_dev   app_d_1012278439994707968_dev   app_d_1018687570684260352_dev   app_d_1034828040540999680_dev   ibtmp1               mysql-bin.000115   mysql-bin.000141   public_key.pemapp_1945102188569_laodian_dev   app_725581508608_test_tt1_dev   app_d_1005739323465752576_dev   app_d_1010924624027447296_dev   app_d_1012278563198193664_dev   app_d_1019055184992382976_dev   app_d_1036464803857166336_dev  '#innodb_redo'        mysql-bin.000116   mysql-bin.000142   server-cert.pemapp_195062153216_default_test   app_791453638656_default_test   app_d_1006012396081340416_dev   app_d_1011079920993562624_dev   app_d_1013338123723853824_dev   app_d_1019873200897794048_dev   app_d_1036519544385974272_dev  '#innodb_temp'        mysql-bin.000117   mysql-bin.000143   server-key.pemapp_196571193344_default_test   app_816690434048_default_test   app_d_1006122233230352384_dev   app_d_1011104587242401792_dev   app_d_1013338201851154432_dev   app_d_1023842551653220352_dev   app_d_1036519946628116480_dev   lcdp                 mysql-bin.000118   mysql-bin.000144   sysapp_2138032611328_default_dev   app_8227738279612416_test_dev   app_d_1006132308405739520_dev   app_d_1011106345658216448_dev   app_d_1013338422039531520_dev   app_d_1024219997648994304_dev   app_d_1037656375662415872_dev   lcdp_erm             mysql-bin.000119   mysql-bin.000145   undo_001app_218821236633600_db_sq_dev   app_825204518744064_test1_dev   app_d_1006446232452059136_dev   app_d_1011149288259579904_dev   app_d_1013358153484193792_dev   app_d_1024231818401431552_dev   app_d_1040171117312413696_dev   lcdp_run             mysql-bin.000120   mysql-bin.000146   undo_002app_227738279612416_test_test   app_847371726848_default_test   app_d_1006448431248822272_dev   app_d_1011164197059948544_dev   app_d_1014489244858773504_dev   app_d_1024232357008785408_dev   app_od_974142457073610752_dev   master-bin.index     mysql-bin.000121   mysql-bin.000147   zzh_map_demoapp_233230352384_default_test   app_86488617971712_shucun_dev   app_d_1006457700924903424_dev   app_d_1011166023419293696_dev   app_d_1014528247108661248_dev   app_d_1024565990860390400_dev   app_od_975232884835905536_dev   mysql                mysql-bin.000122   mysql-bin.000148   zzh_map_demo2app_233238469062656_test_test   app_9233238469062656_test_dev   app_d_1006458292971884544_dev   app_d_1011167920884674560_dev   app_d_1014805207286214656_dev   app_d_1024566471858978816_dev   app_od_978592102489714688_dev   mysql-bin.000097     mysql-bin.000123   mysql-bin.000149app_308405739520_default_test   app_945102188544_default_test   app_d_1006459888120221696_dev   app_d_1011177196571193344_dev   app_d_1014827357393055744_dev   app_d_1024572042514006016_dev   app_od_978825127492251648_dev   mysql-bin.000098     mysql-bin.000124   mysql-bin.000150app_3238079225856_default_dev   app_979078004736_default_test   app_d_1006460401544974336_dev   app_d_1011189251336433664_dev   app_d_1014834673609797632_dev   app_d_1024572572867506176_dev   app_od_999137055907729408_dev   mysql-bin.000099     mysql-bin.000125   mysql-bin.000151app_335215267840_default_test   app_98871352568696832_ddd_dev   app_d_1006460812259610624_dev   app_d_1011191239532998656_dev   app_d_1014837617249759232_dev   app_d_1024573190734086144_dev   app_od_999244520643506176_dev   mysql-bin.000100     mysql-bin.000126   mysql-bin.000152app_396081340416_default_test   app_9962294104064_default_dev   app_d_1006751033644433408_dev   app_d_1011204323920179200_dev   app_d_1016166193735675904_dev   app_d_1024579370265620480_dev   app_od_999244709634650112_dev   mysql-bin.000101     mysql-bin.000127   mysql-bin.000153app_408964583424_default_test   app_d_1004300925747666944_dev   app_d_1006755011660759040_dev   app_d_1011205372915609600_dev   app_d_1016186488617971712_dev   app_d_1024579487827230720_dev   app_sc_prod                     mysql-bin.000102     mysql-bin.000128   mysql-bin.000154app_4623921942528_default_dev   app_d_1004301437498892288_dev   app_d_1007182270792089600_dev   app_d_1011220072671866880_dev   app_d_1016198049780740096_dev   app_d_1024580960116015104_dev   app_st_993335847371726848_dev   mysql-bin.000103     mysql-bin.000129   mysql-bin.000155app_4689726349312_default_dev   app_d_1004302221812768768_dev   app_d_1009283816690434048_dev   app_d_1011435482344189952_dev   app_d_1016218821236633600_dev   app_d_1024582367277088768_dev   app_szxc                        mysql-bin.000104     mysql-bin.000130   mysql-bin.000156app_488617971712_default_test   app_d_1004302307896664064_dev   app_d_1010401188190236672_dev   app_d_1011438016030961664_dev   app_d_1016591945580949504_dev   app_d_1024592473556127744_dev   auto.cnf                        mysql-bin.000105     mysql-bin.000131   mysql-bin.000157app_512927195136_default_test   app_d_1004304082401828864_dev   app_d_1010436753635815424_dev   app_d_1011459951754342400_dev   app_d_1016615229982781440_dev   app_d_1027746486259798016_dev   ca-key.pem                      mysql-bin.000106     mysql-bin.000132   mysql-bin.000158

binlog是二进制文件,直接用文本解析会存在一些乱码。使用mysqlbinlog工具处理后在可以正常读取。mysqlbinlog工具一般安装mysql的时候会默认安装。

mysqlbinlog --base64-output=DECODE-ROWS --start-datetime='2023-11-20 09:00:00' --stop-datetime='2023-11-20 11:00:00' /data/mysql/data/mysql-bin.000161 > mysqllog5.log

其中由于格式是ROW格式,如果直接导出,执行的sql语句会变成类似base64加密后格式样式。

所以追加了 --base64-output=DECODE-ROWS,就是为了转换成明文sql。

其他的start-datetime什么的都好理解,就不在说明了。

如果输出文件显示,应该是没有符合条件的数据。例如下面这个就是由于对应binlog的文件中不包含指定时间段的数据导致的。这时可以切换binlog目录测试。简单点看一下输出文件大小就可以知道是否包含有效数据了。

# The proper term is pseudo_replica_mode, but we use this compatibility alias
# to make the statement usable on server versions 8.0.24 and older.
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
DELIMITER ;
# End of log file
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;

上图就是没有数据的文件大小,不足1k。

log4和log5条件一致,不过log5把ROW解码了,所以文件小了非常多。--base64-output=DECODE-ROWS就是这个的作用。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/197694.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

文件加密软件哪个好丨2023年最值得收藏的6款文件加密软件

文件加密软件哪个好? 在这个安全事件频发的时代,信息安全、文件安全已成为很多人关注的话题。不管是电脑还是手机,都需要重视文件加密这个话题。 那今天就推荐6款最值得收藏的文件加密软件,并分析其中的优缺点。 一、电脑加密软…

【原创】CentOS7.9解决mdadm组raid阵列后resync非常慢的问题

前言 前几日我买了4块16TB的硬盘使用mdadm组了一个raid10阵列,具体如何搭建的可以看我之前的博客。 【报错记录】疯狂踩坑之RockyLinux创建Raid1镜像分区,Raid分区在重启后消失了!外加华硕主板使用Raid模式后,硬盘在系统中无法找…

微信小程序配置企业微信的在线客服

配置企业微信后台 代码实现 <button tap"openCustomerServiceChat">打开企业微信客服</button>methods: {openCustomerServiceChat(){wx.openCustomerServiceChat({extInfo: {url: 你刚才的客服地址},corpId: 企业微信的id,showMessageCard: true,});} …

多域名SSL证书的优势

当今数字化时代&#xff0c;网站拥有一个或多个域名是非常常见的。多域名SSL证书在这样的情境下变得至关重要。它为拥有多个域名的网站提供了全面的安全性和灵活性&#xff0c;为其提供了诸多优势。 多域名SSL证书是一种单个证书&#xff0c;可以为一个域名、多个域名&#xff…

005 OpenCV直方图

目录 一、环境 二、直方图原理概述 三、代码 一、环境 本文使用环境为&#xff1a; Windows10Python 3.9.17opencv-python 4.8.0.74 二、直方图原理概述 OpenCV是一个广泛使用的开源计算机视觉库&#xff0c;它提供了许多用于图像处理和分析的函数和算法。其中&#xff…

单链表相关面试题--1.删除链表中等于给定值 val 的所有节点

/* 解题思路&#xff1a;从头节点开始进行元素删除&#xff0c;每删除一个元素&#xff0c;需要重新链接节点 */ struct ListNode* removeElements(struct ListNode* head, int val) {if(head NULL)return NULL;struct ListNode* cur head;struct ListNode* prev NULL;while…

1.并发编程基础

目录 概述线程和进程并发和并行线程上下文切换线程的一生wait与sleep的区别 结束 概述 线程和进程 进程&#xff1a;是指内存运行的一个应用程序&#xff0c;是系统运行程序的基本单位&#xff0c;是程序的一次执行过程线程&#xff1a;是进程中的一个执行单元&#xff0c;负…

大力说企微入门系列第二课:搭建体系

对于大部分人来说&#xff0c;学习有三动&#xff1a; 学习之前非常激动&#xff1b; 学习时候非常感动&#xff1b;学习之后是一动不动&#xff1b; 不知道大家看了上一课的《大力说企微入门系列第一课&#xff1a;企业微信的注册验证和认证》之后&#xff0c;是一动不动还是…

在电脑PC端可以分类记笔记的软件选择哪个?

选择用电脑来记录笔记是比较便捷的&#xff0c;电脑屏幕比较大&#xff0c;操作起来比较便捷。但是很多人用电脑来记录笔记&#xff0c;通常会使用电脑上自带的记事本、文档记事工具来整合笔记&#xff0c;打开文档记事本类的软件&#xff0c;密密麻麻的文字呈现出来。 选择用…

剪辑视频怎么把说话声音转成文字?

短视频已然成为了一种生活潮流&#xff0c;我们每天都在浏览各种短视频&#xff0c;或者用视频的形式记录生活&#xff0c;在制作视频的时候&#xff0c;字幕是一个很大的问题&#xff0c;给视频添加字幕可以更直观、更方便浏览。手动添加太费时间&#xff0c;下面就给大家分享…

想做副业在哪里找?做好这些副业平台就够了

每个人在生活中都有一些额外的需求和理想&#xff0c;所以越来越多的人开始寻找副业来实现小目标。但是&#xff0c;但是寻找副业的过程并不容易&#xff0c;需要考虑到自己的时间和能力&#xff0c;还有选择一个靠谱的平台。其实&#xff0c;副业平台并不太难&#xff0c;只要…

【LeetCode刷题】--9.回文数

9.回文数 class Solution {public boolean isPalindrome(int x) {if(x < 0){return false;}int tmp x, sum 0;boolean flag false;while(x ! 0){sum sum * 10 x % 10;x / 10;}if(sum tmp){flag true;}return flag;} }