How to Use binlog to restore valid data after MySQL Data is lost

Source: Internet
Author: User
Tags mysql delete

How to Use binlog to restore valid data after MySQL Data is lost

Enable binlog, edit the my. cnf file, and add

Log-bin = mysql-bin # enable the binary log and specify the path and file name, if not set, by default in the data storage directory, the name is hostname-bin.xxxxx

Create a test database, create a table, and insert some data

Mysql> create database student;
Mysql> use student;
Mysql> create table student (id int, name varchar (10), age int );
Mysql> insert into student values ('1', 'tanglu', '28'), ('2', 'zouxiaolu', '28'), ('3 ', 'beibei ', '28 ');

Perform a complete backup so that the first three data items have been backed up.

Mysqldump-u root-p student> student. SQL

Insert 4, 5, and 6 data

Mysql> insert into student values ('4', 'douu', '8 ');
Query OK, 1 row affected (0.01 sec)

Mysql> insert into student values ('5', 'mengmeng', '28 ');
Query OK, 1 row affected (0.00 sec)

Mysql> insert into student values ('6', 'hahaha', '10 ');
Query OK, 1 row affected (0.01 sec)

Accidentally deleted the previously created data.

Mysql> delete from student;

Restart the database once or execute the database statement flush-logs to obtain a new binary log file, so that all the fault logs are in the previous file.

Mysql> flush logs;

Use the first backup to restore data, so that the first three data records are successfully restored.

Mysql-u root-p student <student. SQL

View binlog logs, analyze the position or operation time of some normal operations, and then export and restore these logs.

Hostname-bin.000001 for mysqlbinlog
Mysqlbinlog server1-bin.000003 -- start-position = 1170 -- stop-position = 1294> server2. SQL

Finally, go to the database and check that the data has been restored by entry!

Practices for restoring data using MySQL binlog

MySQL uses binlog to restore Data

MySQL uses backup and binlog for data recovery

MySQL Data Recovery-binlog

Clear binlog logs in MySQL

How to safely delete binlog logs under MySQL

MySQL -- binlog log data recovery

How does MySQL Delete binlog and restore Data?

Introduction and Analysis of Three MySQL binlog formats

MySQL uses binlog Incremental backup + restore instance

MySQL deletes binlog logs and restores data.

This article permanently updates the link address:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.