bitsCN.com
通过BINLOG日志查找指定日期的SQL语句
在95数据库服务器查找posts.post_thread的postid=1652971,在 2013-02-24 日执行的对数据有修改的SQL语句
www.bitsCN.com
# grep datadir /etc/mysql/my.cnf
datadir = /ssd/mysql
# cd /ssd/mysql
# mysql -A -e "show master status " | awk 'NR==2{print $1}' | awk -F. '{print $1}'
mysqld-bin 这里的内容为mysqlbinlog日志的前缀,因为如果是从数据库,还会有replylog.
找Binlog日志,取前一天的最后一个日志,以及24号创建的所有的日志
# ls –l
…
-rw-rw---- 1 mysql mysql 1075302338 Feb 22 04:00 mysqld-bin.000035
-rw-rw---- 1 mysql mysql 1092104643 Feb 22 14:10 mysqld-bin.000036
-rw-rw---- 1 mysql mysql 1073742083 Feb 23 00:06 mysqld-bin.000037
-rw-rw---- 1 mysql mysql 1073742129 Feb 23 05:26 mysqld-bin.000038
-rw-rw---- 1 mysql mysql 1073742102 Feb 23 15:30 mysqld-bin.000039
-rw-rw---- 1 mysql mysql 1073742095 Feb 24 01:36 mysqld-bin.000040
-rw-rw---- 1 mysql mysql 1076478877 Feb 24 09:00 mysqld-bin.000041
-rw-rw---- 1 mysql mysql 1087015180 Feb 24 15:00 mysqld-bin.000042
-rw-rw---- 1 mysql mysql 1073742090 Feb 25 01:31 mysqld-bin.000043
-rw-rw---- 1 mysql mysql 1073742037 Feb 25 08:47 mysqld-bin.000044
-rw-rw---- 1 mysql mysql 1073741919 Feb 25 15:45 mysqld-bin.000045
-rw-rw---- 1 mysql mysql 1073742218 Feb 26 03:36 mysqld-bin.000046
-rw-rw---- 1 mysql mysql 689342483 Feb 26 09:45 mysqld-bin.000047
…
这个时候我们需要分析的binlog日志为mysqld-bin.0000{39,4[0-2]}
# ls mysqld-bin.0000{39,4[0-2]}
mysqld-bin.000039 mysqld-bin.000040 mysqld-bin.000041 mysqld-bin.000042
# cat /root/findsql.sh
#!/bin/bash
BINLOGDIR=`cat /etc/mysql/my.cnf | grep datadir | awk '{print $3}'`
MYSQL="/usr/bin/mysql -A -e "
DATABASE="posts"
cd "${BINLOGDIR}"
BINLOGS=`ls mysqld-bin.0000{39,4[0-2]}`
for i in ${BINLOGS}
do
${MYSQL} "show binlog events in '${i}'" | grep "Query">>"${BINLOGDIR}/${i}.sql"
done
# chmod 755 /root/findsql.sh
先把binlog日志导出来,别做任何修改。至少这样的语句我们就认识了,然后再来搜索我们需要的语句。 www.bitsCN.com
# /root/findsql.sh
# ls mysqld-bin.0000{39,4[0-2]}.sql
mysqld-bin.000039.sql mysqld-bin.000041.sql
mysqld-bin.000040.sql mysqld-bin.000042.sql
在这些SQL中对数据进行筛选,这里的筛选需要看你自己的能力了,
会awk sed grep这三个就够了,awk建议必会。grep平时用的也特别多,应该不难。
# cat /root/parsesql.sh
#!/bin/bash
for i in `ls mysqld-bin.0000{39,4[0-2]}.sql`
do
awk -F 'use `posts`; ' '{print $2}' $i | grep -v 'chapterclick=chapterclick' | grep -v 'novelscore=novelscore' | grep 1652971 >> 1652971.sql
echo $i
done
# chmod 755 /root/parsesql.sh
# /root/parsesql.sh
1652971.sql这个里面的内容就是我们最后的成果
bitsCN.com

TodropaviewinMySQL,use"DROPVIEWIFEXISTSview_name;"andtomodifyaview,use"CREATEORREPLACEVIEWview_nameASSELECT...".Whendroppingaview,considerdependenciesanduse"SHOWCREATEVIEWview_name;"tounderstanditsstructure.Whenmodifying

MySQLViewscaneffectivelyutilizedesignpatternslikeAdapter,Decorator,Factory,andObserver.1)AdapterPatternadaptsdatafromdifferenttablesintoaunifiedview.2)DecoratorPatternenhancesdatawithcalculatedfields.3)FactoryPatterncreatesviewsthatproducedifferentda

ViewsinMySQLarebeneficialforsimplifyingcomplexqueries,enhancingsecurity,ensuringdataconsistency,andoptimizingperformance.1)Theysimplifycomplexqueriesbyencapsulatingthemintoreusableviews.2)Viewsenhancesecuritybycontrollingdataaccess.3)Theyensuredataco

TocreateasimpleviewinMySQL,usetheCREATEVIEWstatement.1)DefinetheviewwithCREATEVIEWview_nameAS.2)SpecifytheSELECTstatementtoretrievedesireddata.3)Usetheviewlikeatableforqueries.Viewssimplifydataaccessandenhancesecurity,butconsiderperformance,updatabil

TocreateusersinMySQL,usetheCREATEUSERstatement.1)Foralocaluser:CREATEUSER'localuser'@'localhost'IDENTIFIEDBY'securepassword';2)Foraremoteuser:CREATEUSER'remoteuser'@'%'IDENTIFIEDBY'strongpassword';3)Forauserwithaspecifichost:CREATEUSER'specificuser'@

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

Dreamweaver Mac version
Visual web development tools

SublimeText3 Chinese version
Chinese version, very easy to use

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version
Recommended: Win version, supports code prompts!
