The job requires that you compare the database (MySQL) data and finish writing the test script. You want to modify a piece of data in a table, and then run the program to see the effect. The correct SQL update table1 set amount = 100 where id=123;
. But the actual situation is not written in the Where condition, press the carriage return, theshell quickly returned "* * Data has been modified", dizzy. Fortunately, I am not a DBA, I only have permission to move the test library, but the test library is also more than 10 people common. Look at the next time 21:30, the others are off work, do not worry about their own slowly.
No backup
Database misoperation, data recovery first think of backup, test library is generally a copy of online data, there are few backups, methods do not pass.
Binlog full volume recovery too difficult
Roughly know the MySQL binlog log, recording all the operations. About Binlog There are several commands that are useful to record:
show variables like ‘log_%‘;
See if Binlog is open
Mysql> Show variables like ' log_% '; +----------------------------------------+---------------------------------- ------+| variable_name | Value |+----------------------------------------+---------------------------------------- +| Log_bin | On | | Log_bin_basename | /home/somename/mysql-bin | | Log_bin_index | /home/somename/test/mysql-bin.index | | log_bin_trust_function_creators | OFF | | log_bin_use_v1_row_events | OFF | | Log_error | /home/somename/test/err.log | | Log_output | FILE | | log_queries_not_using_indexes | On | | Log_slave_updates | On | | log_slow_admin_statements | OFF | | log_slow_slave_statements | OFF | | log_throttle_queries_not_using_indexes | 0 | | log_warnings | 1 | +----------------------------------------+----------------------------------------+13 rows in Set (0.00 sec)
show binary logs;
View a list of the Binlog files in the MySQL database (these logs are mostly large)
Mysql> Show binary logs;+------------------+------------+| Log_name | File_size |+------------------+------------+| mysql-bin.000067 | 1074104507 | | mysql-bin.000068 | 1073900275 | | mys ql-bin.000069 | 1073742040 | | mysql-bin.000070 | 1073742234 | | mysql-bin.000071 | 1074693303 | | mysql-bin.000072 | 1074476163 | | mysql-bin.000073 | 1073743892 | | mysql-bin.000074 | 1073742728 | | mysql-bin.000075 | 76346728 | +------------------+------------+9 rows in Set (0.01 sec)
' Show master status \g; ' View the currently used Binlog file
Mysql> Show Master Status \g;*************************** 1. Row *************************** file:mysql-bin.000075 position:76352042 binlog_do_db:binlog_ignore_ Db:executed_gtid_set:1 row in Set (0.00 sec)
' Show binlog events; ' MySQL console view the currently used Binlong
After this command is entered, it is basically a full-screen scrolling log, with nearly 1G of log output in the MySQL console, cautiously. These logs record SQL, time, and number of rows for all operations that have been modified for the database.
show binlog events in ‘mysql-bin.000002‘;
View the specified binlog.
mysqlbinlog --stop-date="2005-04-20 9:59:59" /var/log/mysql/bin.123456
Recover logs from Binlog, Mysqlbinlog is not a mysql console command, is a recovery tool provided by MySQL and needs to be executed under shell or cmd
Because you do not have permission to log on to the MySQL machine, you can only execute commands through the MySQL connection. Unable to get the Binlog log directly from the database server. MySQL provides the-e parameter (which was not known before) to redirect the mysql -u root -p root -e "show binlog events" > bin.log
log to a file.
The machine got the current library binlog, but completely no backup, using Binlog to recover data, only the database from the creation to the present generation of Binlog all executed once, this tangled, Binlog too big And then even if we have the patience and time to execute all the SQL in Binlog, we cannot guarantee that binlog from creation to now no one deleted, after all, backup of the log, generally not put too long:(
Continue reading,
Data recovery after a database error update