【数据库】mysql删库恢复

删库跑路撤回手册

1.binlog恢复

1.查看mysql是否开启binlog日志

mysql> show variables like 'log_%';

2.查看logs文件并查看二进制操作日志

mysql> show libary logs;

[root@test mysql] #mysqlbinlog --start-position=0 /mydata/data/mysql-bin.000089

Warning: option 'start-position': unsigned value 0 adjusted to 4


/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;

/*!40019 SET @@session.max_insert_delayed_threads=0*/;

/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;

DELIMITER /*!*/;

# at 4

#151022 18:00:43 server id 1 end_log_pos 107  Start: binlog v 4, server v 5.5.38-log created 151022 18:00:43 at startup

# Warning: this binlog is either in use or was not closed properly.

ROLLBACK/*!*/;

BINLOG '

y7MoVg8BAAAAZwAAAGsAAAABAAQANS41LjM4LWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

AAAAAAAAAAAAAAAAAADLsyhWEzgNAAgAEgAEBAQEEgAAVAAEGggAAAAICAgCAA==

'/*!*/;

# at 107

#151022 23:27:50 server id 1 end_log_pos 198  Query  thread_id=2   exec_time=0   error_code=0

SET TIMESTAMP=1445527670/*!*/;

SET @@session.pseudo_thread_id=2/*!*/;

SET @@session.foreign_key_checks=0, @@session.sql_auto_is_null=0, @@session.unique_checks=0, @@session.autocommit=1/*!*/;

SET @@session.sql_mode=1608515584/*!*/;

SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;

/*!\\\\C utf8 *//*!*/;

SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=8/*!*/;

SET @@session.lc_time_names=0/*!*/;

SET @@session.collation_database=DEFAULT/*!*/;

DROP SCHEMA IF EXISTS `pandora`
/*!*/;

# at 198

#151022 23:27:50 server id 1 end_log_pos 346  Query  thread_id=2   exec_time=0   error_code=0

3.通过Bin log恢复数据. 把历史的bin-log都重新执行了一遍,重新恢复到误删以前的版本,(这里总共有91个文件,批量处理的):(9999999999999:是为了省掉去查找每一个bin-log日志文件的起始结束位置,设的一个无穷大的数字,简化操作.)


#mysqlbinlog /var/lib/mysql/mysql-bin.000001 --start-position=0 --stop-position=9999999999999 | mysql -uroot -p123456

#mysqlbinlog /var/lib/mysql/mysql-bin.000002 --start-position=0 --stop-position=9999999999999 | mysql -uroot -p123456

#mysqlbinlog /var/lib/mysql/mysql-bin.000003 --start-position=0 --stop-position=9999999999999 | mysql -uroot -p123456

... ...

总结:mysql最佳是有dump备份恢复,其次开启binlog文件用日志恢复

你可能感兴趣的:(#,sql/数据库,mysql,数据库)