1、找到最新的 binlog 文件
进入 mysql 命令行执行如下命令
mysql> show master status; +------------------+-----------+ | Log_name | File_size | +------------------+-----------+ | binlog.000001 | 967 | | binlog.000002 | 965 | +------------------+-----------+
一般最新的编号大,上面最新的就是 binlog.000002
2、找到我们想恢复数据在日志文件里的开始结束位置
这里有两种方式来确定开始位置和结束位置,一种是使用时间作为开始结束,一种是使用日志的 position 作为开始结束位置
2.1、使用时间范围
通过 mysqlbinlog mysql-bin.000002 命令查看日志内容,然后找到删除的时间点:
# at 131708213 #210610 11:27:01 server id 1 end_log_pos 131708311 CRC32 0x0fc755e2 Table_map: `loongwind_base`.`xxxx` mapped to number 139 # at 131708311 #210610 11:27:01 server id 1 end_log_pos 131708411 CRC32 0xa91616b9 Write_rows: table id 139 flags: STMT_END_F BINLOG ' BffBYBMBAAAAYgAAAJe12QcAAIsAAAAAAAEADmR4bWhfYmFzZV9oenN5ABpkeF9zeV9hc3NldHNf ZXh0ZW5kc19jb3B5MQAICAgIDwgSCBIEAAgAAPgBAQACA/z/AOJVxw8= BffBYB4BAAAAZAAAAPu12QcAAIsAAAAAAAMAAgAI/wDRAwAAm1M8AUIAAADRUjwBCgAAAFYL5gAM AOWFrOWuieacuuWFs7EBAADbwZkAmama6E+xAQAA28GZAJmpmuhPuRYWqQ== '/*!*/;
然后确定上次备份的时间点,如果通过日志找不到上次备份的时间点可以填一个你记忆中确定小于上次备份的时间点
2.2、使用 position 范围
使用如下命令查看日志 event 的 position
mysql -uroot -p'password' -e "show binlog events in 'binlog.000002'"|grep -i 'DROP TABLE'
执行结果如下:
binlog.000002 820474948 Query 1 820475111 use `loongwind_base`; DROP TABLE IF EXISTS `undo_log` /* generated by server */ /* xid=11790691 */
即删除的 position 为 820474948
还是通过上述命令,替换关键字查找到上次备份的 position 点
3、恢复
3.1 通过时间恢复
mysqlbinlog --no-defaults --database=loongwind_base --start-datetime="2021-06-07 09:00:00" --stop-datetime="2021-06-10 16:37:58" binlog.000005 | mysql -uroot -p'password' -s -N -f -D loongwind_base
其中 dxmh_base_hzsy 是数据库名称
3.2 通过 position 恢复
mysqlbinlog --start-position=1178 --stop-position=2751 -d dxmh-sy binlog.000002|mysql -uroot -p'password' -s -N -f -D loongwind_base loongwind_base 为数据库名称
如果实在找不到开始时间或者开始 position 也可以不写 --start-datetime 或 --start-position ,这样就是用这个日志文件的开始一直恢复到结束,为了防止与已有数据的冲突,需要加上 -f 即 force 跳过错误继续往下执行。
以上是怎么通过日志文件恢复MySQL数据的详细内容。更多信息请关注PHP中文网其他相关文章!

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

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

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

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

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

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

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

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


热AI工具

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

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

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

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

热门文章

热工具

Atom编辑器mac版下载
最流行的的开源编辑器

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

禅工作室 13.0.1
功能强大的PHP集成开发环境

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

Dreamweaver Mac版
视觉化网页开发工具