搜索
首页数据库mysql教程通过BINLOG日志查找指定日期的SQL语句_MySQL

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
声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
在MySQL中使用视图的局限性是什么?在MySQL中使用视图的局限性是什么?May 14, 2025 am 12:10 AM

mysqlviewshavelimitations:1)他们不使用Supportallsqloperations,限制DatamanipulationThroughViewSwithJoinSorsubqueries.2)他们canimpactperformance,尤其是withcomplexcomplexclexeriesorlargedatasets.3)

确保您的MySQL数据库:添加用户并授予特权确保您的MySQL数据库:添加用户并授予特权May 14, 2025 am 12:09 AM

porthusermanagementInmysqliscialforenhancingsEcurityAndsingsmenting效率databaseoperation.1)usecReateusertoAddusers,指定connectionsourcewith@'localhost'or@'%'。

哪些因素会影响我可以在MySQL中使用的触发器数量?哪些因素会影响我可以在MySQL中使用的触发器数量?May 14, 2025 am 12:08 AM

mysqldoes notimposeahardlimitontriggers,butacticalfactorsdeterminetheireffactective:1)serverConfiguration impactactStriggerGermanagement; 2)复杂的TriggerSincreaseSySystemsystem load; 3)largertablesslowtriggerperfermance; 4)highConconcConcrencerCancancancancanceTigrignecentign; 5); 5)

mysql:存储斑点安全吗?mysql:存储斑点安全吗?May 14, 2025 am 12:07 AM

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

mySQL:通过PHP Web界面添加用户mySQL:通过PHP Web界面添加用户May 14, 2025 am 12:04 AM

通过PHP网页界面添加MySQL用户可以使用MySQLi扩展。步骤如下:1.连接MySQL数据库,使用MySQLi扩展。2.创建用户,使用CREATEUSER语句,并使用PASSWORD()函数加密密码。3.防止SQL注入,使用mysqli_real_escape_string()函数处理用户输入。4.为新用户分配权限,使用GRANT语句。

mysql:blob和其他无-SQL存储,有什么区别?mysql:blob和其他无-SQL存储,有什么区别?May 13, 2025 am 12:14 AM

mysql'sblobissuitableForStoringBinaryDataWithInareLationalDatabase,而alenosqloptionslikemongodb,redis和calablesolutionsoluntionsoluntionsoluntionsolundortionsolunsolunsstructureddata.blobobobsimplobissimplobisslowderperformandperformanceperformancewithlararengelitiate;

mySQL添加用户:语法,选项和安全性最佳实践mySQL添加用户:语法,选项和安全性最佳实践May 13, 2025 am 12:12 AM

toaddauserinmysql,使用:createUser'username'@'host'Indessify'password'; there'showtodoitsecurely:1)choosethehostcarecarefullytocon trolaccess.2)setResourcelimitswithoptionslikemax_queries_per_hour.3)usestrong,iniquepasswords.4)Enforcessl/tlsconnectionswith

MySQL:如何避免字符串数据类型常见错误?MySQL:如何避免字符串数据类型常见错误?May 13, 2025 am 12:09 AM

toAvoidCommonMistakeswithStringDatatatPesInMysQl,CloseStringTypenuances,chosethirtightType,andManageEngencodingAndCollat​​ionsEttingsefectery.1)usecharforfixed lengengters lengengtings,varchar forbariaible lengength,varchariable length,andtext/blobforlabforlargerdata.2 seterters seterters seterters seterters

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

螳螂BT

螳螂BT

Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

将Eclipse与SAP NetWeaver应用服务器集成。

VSCode Windows 64位 下载

VSCode Windows 64位 下载

微软推出的免费、功能强大的一款IDE编辑器