MySQL Data Recovery

Source: Internet
Author: User

When a customer updates data, the database content is deleted by mistake, because the database is master-slave, but not backup (backup is very important !) Fortunately, the bin-log is enabled, and the entire log record has to be taken back to the local for recovery.

Then I did a simple test to restore the data as follows:

1. Create a new table
Create table 'lynn '. 'sn _ test' ('name' VARCHAR (10) character set utf8 COLLATE utf8_bin not null, 'age' INT (3) not null) ENGINE = MYISAM;

2. Insert multiple data entries
Insert into 'lynn '. 'sn _ test' ('name', 'age') VALUES ('lynn1', '1 ');
Insert into 'lynn '. 'sn _ test' ('name', 'age') VALUES ('lynn2', '2 ');
Insert into 'lynn '. 'sn _ test' ('name', 'age') VALUES ('lynn3', '3 ');
Insert into 'lynn '. 'sn _ test' ('name', 'age') VALUES ('lynn4', '4 ');

3. View and delete data
Mysql> select * from sn_test;
+ ------- + ----- +
| Name | age |
+ --------- + --- +
| Lynn1 | 1 |
| Lynn2 | 2 |
| Lynn3 | 3 |
| Lynn4 | 4 |
+ --------- + ----- +
4 rows in set (0.00 sec)

Mysql> delete from sn_test;
Query OK, 4 rows affected (0.00 sec)

Mysql> select * from sn_test;
Empty set (0.00 sec)

4. Restore data using mysqlbinlog
Mysqlbinlog mysql-bin.000006> 1. SQL
Records inserted into the TXT file to restore the deleted data.
Mysqlbinlog mysql-bin.000006 -- start-position = 2471 -- stop-position = 2876 | mysql-uroot-p123

Log On again to view the data. OK. The data has been successfully restored.

Pay attention to the following issues for database operations:
1. Always back up (full backup, Incremental Backup). If something goes wrong, you can restore the data as quickly as possible;
2. dump the database or table to be operated before operating the database;
3. You need to open the bin-log. Even if you have not done the above two steps, you can restore data through the log.

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.