mysql data backup is not how to restore accidentally deleted

Open the mysql bin log function:
for mysql also supports incremental backups, but you want to open the mysql bin log function.
We modify the mysql configuration file. linux is /etc/my.cnf,windows is mysql installation directory /my.ini
we add log-bin line to the [mysqld] Next, as described below.

[mysqld]

log-bin bin = mysql-

duplicated code
After addition mysql to restart.

A customer update data when mistakenly deleted the contents of the database, because the database did a master-slave, but did not do a backup (Backup is very important ah!) Fortunately, opened the bin-log, then had to record the entire log to get it back locally restore.

After he is done with a simple test, data recovery, as follows:
1, create a new table
CREATE TABLE `lynn`.`sn_test` (` name` VARCHAR (10) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `age the INT `(. 3) the NOT NULL) ENGINE = MYISAM;
2, a plurality of data inserted into
the iNSERT lynn`.`sn_test` the INTO` ( `name`,` age`) the VALUES ( 'lynn1', '. 1');
the iNSERT the INTO ` lynn`.`sn_test` ( `name`,` age`) VALUES ( 'lynn2', '2');
The INTO `lynn`.`sn_test` the INSERT (name``, `age`) the VALUES ( 'lynn3', '. 3');
the INSERT lynn`.`sn_test` the INTO` ( `name`,` age`) the VALUES ( ' lynn4 ',' 4 ');
3, view the data and delete
MySQL> the SELECT * from sn_test;
+ ------- + ----- +
| name | Age |
+ -------- - + --- +
| lynn1 | 1 |
| lynn2 | 2 |
| lynn3 | 3 |
| lynn4 | 4 |
+ --------- + ----- +
4 rows in the SET (0.00 sec )
MySQL> the Delete from sn_test;
Query the OK, 4 rows affected (0.00 sec)
MySQL> the SELECT * from sn_test;
Empty the SET (0.00 sec)
4, mysqlbinlog recover data
mysqlbinlog mysql-bin.000006> 1.sql
View 1.txt inside insert data records, delete the data before recovery
mysqlbinlog mysql-bin.000006 --start-position = 2471 --stop-position = 2876 | mysql -uroot -p123
re-login to view the data, OK, has been successfully restored
to the database operations, should pay attention to the following questions:
1, to often backup (full backup, incremental backup), a problem can recover the fastest data;
2, before operating the database or database tables, it is necessary to be operated dump out;
3, need to open bin-log, even if not done above two steps, the data can be restored through the log

Guess you like

Origin www.cnblogs.com/shujutongbu/p/11021029.html
Recommended