In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article is about how to read the start and end time of mysql binlog. I think it is very practical, so I share it with you. I hope you can get something after reading this article.
Mysql binlog records all actions that may involve updates and can be used as an option for incremental backups. To manage binlog, you need to read the exact start and end times of each binlog file. The binlog file can be parsed with the mysqlbinlog tool, so it can also be obtained by analyzing the output. However, mysqlbinlog can only read records sequentially, and if only the analysis start time is good, to analyze the end time, you must wait for it to finish processing the entire binlog. When the size of the binlog file is large, it is a bit more expensive. Fortunately, mysql is open to the format of the binlog file, so we can do it directly by parsing the file ourselves.
The format of the binlog file can be found in http://forge.mysql.com/wiki/MySQL_Internals_Binary_Log. Every binlog file has the same beginning: 0xfe 0 × 620 × 69 0x6e. That is, 0xfe is followed by bin. After that, there is event data one by one. There are many types of events in binlog, but the first event in each binlog file must be a format description event (format description event), describing the binlog file format version information; the last time must be a rotation event (rotate event), recording the file name of the next binlog and the event start offset. Each event has a consistent event header, including the event's timestamp, event type, and so on. By reading the information about the first and last events, you can get the exact start and end times of the binlog file.
It's easier to read the first event format description event. Seek just skip the file header and read the event header. It is a little more troublesome to read the last event. Because the length of the event is not fixed. For rotational events, in addition to the event header, it is followed by a 64-bit integer start position offset and the file name of the next binlog. The part with uncertain length is the last part of the file name. Fortunately, the offset is a fixed value: 4 (that is, skip the header), so you can read it from back to front and use it as a tag to check if you have finished reading the file name. You can then skip the file name and offset and read the event header of the last event.
The code is as follows:
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.