Shell dynamic parsing of SQL Binlog

Source: Internet
Author: User

#!/usr/bin# Setting up a database connection conn='Mysql-hhost-pport-uusername-ppassword'#获取最新的binlog文件logfile=$ ($conn-E"Show Master Logs"|Tail-N1|awk-F" " '{print $}') #设置a为1, the user's bottom of the judgment a=1#while循环 while true Do#获取起始datetime fromdate=$(Date "+%y-%m-%d%h:%m:%s") #获取结束datetime toDate=$(Date "+%y-%m-%d%h:%m:%s"-D'+1 Second' )    Echo "ToDate is", $toDateEcho "a is"$a #设置tempDate的值if[$a-eq1]; Thentempdate=$fromDateElsetempdate=$tmpDatefi    Echo "Start time is"$tempDateEcho "Stop Time is", $toDate #解析binlog, and append to file Mysqlbinlog-r-hhost-pport-uusername-ppassword--start-datetime="$tempDate"--stop-datetime="$toDate"$logfile |grep-V"[#|/*!*/;|begin| Commit|]">>Content.txt #重新设置a的值
A=2tmpdate=$toDateEcho "Current log file is"$logfileDone
Then Tailf Content.txt, you can observe the output of binlog in real time.

Note: Because Content.txt content is appended, you can set up a scheduled task to process the Content.txt file regularly to prevent the file from growing too large
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.