windows 下的mysqlbinlog 数据备份

it2025-12-24  10

1、开启binlog日志功能 找到mysql安装目录:C:\ProgramData\MySQL\MySQL Server 5.7 编辑my.ini文件,在mysqld下面添加:

重启mysql服务:

![在这里插入图片描述](https://img-blog.csdnimg.cn/20201022142906309.png#pic_center 开启成功:

show variables like 'log_bin';

2、创建一张表并删除,然后binlog恢复。 建表:

CREATE TABLE if not exists test4 ( id int UNSIGNED NOT NULL AUTO_INCREMENT , username VARCHAR(3) NOT NULL DEFAULT "张三" , PRIMARY KEY (`id`) )

删除表:

drop table test4;

查看binlog 日志:

show binlog events in 'mysql-bin.000004'

所以要恢复就是找到建表 pos: 在这里插入图片描述 找到log-bin配置位置,我的是F:\mysql-bin 所以进入F: 盘,执行恢复语句: mysqlbinlog --start-position=3857 --stop-position=4226 mysql-bin.000004 > F: \test4.sql 生成的test4.sql就是我们需要的sql文件。 3、登录mysql: mysql -uroot -p111 执行命令: source F:\test4.sql 恢复成功!

最新回复(0)