本篇內(nèi)容介紹了“怎么根據(jù)日期來查詢mysql的binlog日志”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

根據(jù)日期來查詢mysql的binlog日志的腳本
[binlog@m-mysql-binlogbak ~]$ cat mysqllog.sh
#!/bin/bash
#本腳本是用來根據(jù)日期來查詢mysql的binlog日志
#the author is czxin788@qq.com
read -p "請(qǐng)輸入您要查詢mysql日志的起始日期(格式必須是:170728):" starttime
read -p "請(qǐng)輸入您要查詢mysql日志的截止日期(格式必須是:170728):" endtime
read -p "請(qǐng)輸入您要查詢的內(nèi)容:" content
echo "-------------------"
echo "正在為您查詢,時(shí)間可能會(huì)比較長(zhǎng),請(qǐng)您耐心等候....."
echo "開始時(shí)間:`date +%Y-%m-%d_%H:%M`"
#獲取binlog的文件名
binname=`ls /opt/mysqlbinlog/ |xargs`
#用for 循環(huán)根據(jù)開始日期確定要查詢的起始binlog日志文件名
for i in `ls /opt/mysqlbinlog/`
do
mysqlbinlog --base64-output=decode-rows -v -v -v /opt/mysqlbinlog/$i |head -50 |grep `expr $starttime - 1` > /dev/null 2>&1
if [ $? -eq 0 ];then
echo $i > /tmp/startbin.txt
break
fi
done
startbinlog=`cat /tmp/startbin.txt`
fistname=`echo $startbinlog ${binname##*$startbinlog}`
#######
#用for 循環(huán)根據(jù)截止日期確定要查詢的截止binlog日志文件名
for j in `ls /opt/mysqlbinlog/`
do
mysqlbinlog --base64-output=decode-rows -v -v -v /opt/mysqlbinlog/$j |head -50 |grep `expr $endtime + 1` > /dev/null 2>&1
if [ $? -eq 0 ];then
echo $j > /tmp/endbin.txt
break
fi
done
endbinlog=`cat /tmp/endbin.txt`
lastname=`echo ${fistname%%$endbinlog*} $endbinlog`
#輸出最終要查詢的binlog文件名list
#echo the result name:$lastname
cd /opt/mysqlbinlog/
resultlog=${content}_`date +%m%d%H%M%S`.log
mysqlbinlog --base64-output=decode-rows -v -v -v $lastname |grep -C 200 -i $content > /home/binlog/$resultlog
echo "-------------------"
echo "結(jié)束時(shí)間:`date +%Y-%m-%d_%H:%M`"
echo "已完成,您要查詢的內(nèi)容已經(jīng)放在/home/binlog/$resultlog里面,請(qǐng)執(zhí)行sz /home/binlog/$resultlog命令下載到自己筆記本上查看!"
[binlog@m-mysql-binlogbak ~]$ sh mysqllog.sh
就可以使用了
“怎么根據(jù)日期來查詢mysql的binlog日志”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
當(dāng)前題目:怎么根據(jù)日期來查詢mysql的binlog日志-創(chuàng)新互聯(lián)
文章路徑:http://www.chinadenli.net/article10/dccpdo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、手機(jī)網(wǎng)站建設(shè)、標(biāo)簽優(yōu)化、ChatGPT、自適應(yīng)網(wǎng)站、全網(wǎng)營(yíng)銷推廣
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容