Following the below sequence of commands i expected the recovery of backup and subsequent point in time recovery using binary log. However, the database was restored to backup only:


  `ID` int(11) NOT NULL,
  `NAME` varchar(20) NOT NULL,
  `AGE` int(11) NOT NULL,
  `SALARY` decimal(18,2) DEFAULT NULL,

2) INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) VALUES (70, 'Hardik70', 27, 'Bhopal', 8500.00 );

3) mysqldump db -uroot -ppass --master-data=2 > out.sql

4) INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) VALUES (80, 'Hardik80', 27, 'Bhopal', 8500.00 );

5) mysql -uroot -ppass < out.sql


mysqlbinlog --start-position=368315 /var/log/mysql/bin.123456 \
             | mysql -u root -p

/var/log/mysql/bin.123456 and 368315 was taken from out.sql because the dump was done using --master-data=2 option

i expected select * from CUSTOMERS; to return

| 70 | Hardik70 |  27 | Bhopal    | 8500.00 |
| 80 | Hardik80 |  27 | Bhopal    | 8500.00 |

but only | 70 | Hardik70 | 27 | Bhopal | 8500.00 | is returned

How to do point-in-time backup recovery correctly?

1 Answer 1


The point in time recovery actually works, but you forget, that your restoration of the dump also gets written to the binary log and this undoes your point in time recovery.

What you should actually do, is to also note the binary log position before you restore your dump. Then you limit the point in time recovery with --end-position. Your workflow therefore is

  1. create table
  2. insert into table
  3. mysqldump --master-data=2
  4. insert into table
  5. show master status; /* note log file and position */
  6. mysql < out.sql
  7. mysqlbinlog --start-position=368315 --end-position=<note from above> binlog | mysql

Alternatively you can also not write the mysqldump to the binary log. The 6th step would then be

mysql > set session sql_log_bin=0; 
mysql > source out.sql

You have to re-setup slaves then of course.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.