use lijiamandb;create table test01 ( id1 int not null auto_increment, name varchar(30), primary key(id1) );
create table test02 ( id2 int not null auto_increment, name varchar(30), primary key(id2) ); 创建存储过程,往测试表里面插入数据,每次执行该存储过程,往test01和test02各自插入10000条数据:
CREATE DEFINER=`root`@`%` PROCEDURE `p_insert`() BEGIN #Routine body goes here... DECLARE str1 varchar(30); DECLARE str2 varchar(30); DECLARE i int; set i = 0;
while i < 10000 do set str1 = substring(md5(rand()),1,25); insert into test01(name) values(str1); set str2 = substring(md5(rand()),1,25); insert into test02(name) values(str1); set i = i + 1; end while; END 制定事件,每隔10秒钟,执行上面的存储过程:
use lijiamandb; create event if not exists e_insert on schedule every 10 second on completion preserve do call p_insert(); 启动EVENT,每个10s自动向test01和test02各自插入10000条数据
mysql> show variables like '%event_scheduler%'; +----------------------------------------------------------+-------+ | Variable_name | Value | +----------------------------------------------------------+-------+ | event_scheduler | OFF | +----------------------------------------------------------+-------+
mysql> exit Bye [root@masterdb binlog]# mysql -uroot -p123456 lijiamandb < /mysql/backup/lijiamandb.sql mysql: [Warning] Using a password on the command line interface can be insecure. 在执行全量备份恢复之后,发现只有753238笔数据:
[root@masterdb binlog]# mysql -uroot -p123456 lijiamandb
mysql> select count(*) from test01; +----------+ | count(*) | +----------+ | 753238 | +----------+ row in set (0.12 sec)
mysql> select count(*) from test02; +----------+ | count(*) | +----------+ | 753238 | +----------+ row in set (0.11 sec) 很明显,全量导入之后,数据不完整,接下来使用mysqlbinlog对二进制日志执行增量恢复。
# 确认drop database之前的位置为:54号文件的9019487 # at 9019422 #200423 16:07:46 server id 11 end_log_pos 9019487 CRC32 0x86f13148 Anonymous_GTID last_committed=30266 sequence_number=30267 rbr_only=no SET @@SESSION.GTID_NEXT= 'ANONYMOUS'/*!*/; # at 9019487 #200423 16:07:46 server id 11 end_log_pos 9019597 CRC32 0xbd6ea5dd Query thread_id=100 exec_time=0 error_code=0 SET TIMESTAMP=1587629266/*!*/; SET @@session.sql_auto_is_null=0/*!*/; /*!/C utf8 *//*!*/; SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=33/*!*/; drop database lijiamandb /*!*/; # at 9019597 #200423 16:09:25 server id 11 end_log_pos 9019662 CRC32 0x8f7b11dc Anonymous_GTID last_committed=30267 sequence_number=30268 rbr_only=no SET @@SESSION.GTID_NEXT= 'ANONYMOUS'/*!*/; # at 9019662 #200423 16:09:25 server id 11 end_log_pos 9019774 CRC32 0x9b42423d Query thread_id=100 exec_time=0 error_code=0 SET TIMESTAMP=1587629365/*!*/; create database lijiamandb STEP7:确定了开始结束点,执行增量恢复 开始:44号日志的8526828 结束:54号文件的9019487