在mysqld的配置節點下添加以下配置mysql
log-bin="E:/Mysql57BinLog/binlog"(windows下的路徑,linux下自行修改路徑) expire_logs_days=10 max_binlog_size=100M
使用命令show VARIABLES like '%log_bin%';查看linux
create database mytest; use mytest; create table t(a int PRIMARY key)ENGINE = INNODB DEFAULT CHARSET=utf8; flush logs;
flush logs,刷新二進制日誌後會多出來一個二進制日誌sql
使用命令查看二進制日誌內容數據庫
默認會讀取配置文件,檢測到no--beep會報錯。windows
推薦使用命令:mysqlbinlog --no-defaults E:\Mysql57BinLog\binlog.000001bash
use mytest; insert into t select 1 union all select 2 union all select 3; flush logs;
drop database mytest; flush logs;
mysqlbinlog --no-defaults E:\Mysql57BinLog\binlog.000001 E:\Mysql57BinLog\binlog.000002 E:\Mysql57BinLog\binlog.000003 | mysql -u root -p
數據已還原。spa
-----------------------------------華麗的分割線--------------------------------------------------------------3d
create table t2(a int PRIMARY key)ENGINE=INNODB default CHARSET=utf8; insert into t2 values(1),(2),(3),(4),(5); >mysqlbinlog --no-defaults E:\Mysql57BinLog\binlog.000006
刪除數據日誌
delete from t2 where a < 4;
恢復數據code
drop database mytest; 刪除庫mytest,回到最原始的地方 mysqlbinlog --no-defaults --start-position="4" --stop-position="1285" E:\Mysql57BinLog\binlog.000006 | mysql -u root -p
數據恢復成功。