1: Before using the log to confirm that the log is open, log in to the MySQL client,
mysql-uroot-p123456
(If the source is installed and the path to the MySQL bin is not added to the environment variable, you can enter
/usr/local/mysql/bin/mysql-uroot-p123456
or a home directory to configure the. bash_profile file to add the/usr/local/mysql/bin to the environment variable once, enter:
Shou variables like "%bin%",
See if the value of Log_bin is on.
2: Configure the Bin-log log if the above Log_bin value is not on, then edit the MySQL configuration file,
VIM/ETC/MY.CNF,
Join under [mysqld] (note not mysqld_safe) module
Log_bin=/usr/local/mysql/log/mysql-bin
(log must be present, the log file begins with Mysql-bin).
3: Restart the MySQL client,
Service mysqld Restart,
At this point you can see two files in the/usr/local/mysql/log directory, respectively
Mysql-bin.000001 and Mysql-bin.index,
mysql-bin.000001 is to record MySQL and delete data records, log in to the MySQL CLI,
Switch to the test database,
Use Test,
Create a table,
CREATE TABLE TLog (
ID Int (TEN) unsigned NOT NULL
) Engine=innodb default Charset=utf8 collate=utf8_general_ci;
Insert a piece of data:
INSERT into TLog values (13);
To refresh the Bin-log log, enter:
Flust logs,
That's when you get a mysql-bin.000002 file under/usr/local/mysql/log.
4: Now the simulation server crashes, the data is lost, to revert to the previous data, in the MySQL CLI input:
Delete from TLog;
Now delete the data and enter it in the shell CLI:
mysqlbinlog/usr/local/mysql/log/mysql-bin.000001 | mysql-uroot-p123456 Test
(Test is a database, because the log is binary, so the general editor such as VI and Vim cannot be viewed, you can use
mysqlbinlog/usr/local/mysql/log/mysql-bin.000001
To view)
Mysql bin-log Log configuration and recovery data