First, Environment:
A) centos-6.5-x64-bit operating system.
b) Install MySQL. Command: Yum install mysql*
Second, Configuration
A) Configure the/etc/my.cnf file
[Mysqld]
Log-bin=bin-log//Configure turn on log function
Third, Implement
- Check the/var/lib directory for log files that do not resemble bin-log.000001.
- Log in to MySQL execution: Flush logs;//Refresh the log, and then look at the log file, if you do not perform the flush logs and restart MySQL, then all of the MySQL operation will be recorded in the log file after the refresh. Command: Mysqlbinlog–no-defaults bin-log.000001 | More
- Log in to MySQL, create tables, and insert a series of test data as objects to be recovered. Execute the flush logs again to generate the bin-log.000002 log file. The data and tables are then deleted.
- Now restore the data. Open another terminal and execute the command:
Mysqlbinlog–no-defaults bin-log.000001 | Mysql–u root–p
Enter the root password. Return to view, both the table and the data have been restored.
Four, Mysqlbinlog syntax: Time-based (date) and Location (position) the recovery
1. Positioning:--start-position start point
--stop-position End Point
--start-date Start time
--stop-date End Time
2. Example:
Mysqlbinlog–no-defaults–start-position POS Value –stop-position pos value bin-log.000001 | Mysql–u root–p
Note: The positioning keywords can be paired or used alone, to achieve a slight phenomenon.
Original Log rollback for MySQL under CentOS