关系型数据库之Mysql二进制日志管理
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关系型数据库之Mysql二进制日志管理相关的知识,希望对你有一定的参考价值。
mysql二进制日志(Binary Log)
1.它包含的内容及作用如下:
包含了所有更新了数据或者已经潜在更新了数据(比如没有匹配任何行的一个DELETE)
包含关于每个更新数据库(DML)的语句的执行时间信息
不包含没有修改任何数据的语句,如果需要启用该选项,需要开启通用日志功能
主要目的是尽可能的将数据库恢复到数据库故障点,因为二进制日志包含备份后进行的所有更新
用于在主复制服务器上记录所有将发送给从服务器的语句
启用该选项数据库性能降低1%,但保障数据库完整性,对于重要数据库值得以性能换完整。有些类似于Oracle开启归档模式。
2.开启二进制日志的方法及属性
使用--log-bin[=file_name]选项或在配置文件中指定log-bin启动时,mysqld写入包含所有更新数据的SQL命令的日志文件。
对于未给出file_name值,默认名为-bin后面所跟的主机名。
在未指定绝对路径的情形下,缺省位置保存在数据目录下。
每个二进制日志名会添加一个数字扩展名用于日志老化,因此不支持自定义的扩展名,会被mysql数字扩展名动态替换。
若当前的日志大小达到max_binlog_size,则自动创建新的二进制日志。
对于大的事务,二进制日志会超过max_binlog_size设定的值。也即是事务仅仅写入一个二进制日志。
由是可知,二进制日志文件大小接近,其size不是完全相等,这点不同于oracle。
二进制日志文件会有一个对应二进制日志索引文件,该文件包含所有的二进制日志,其文件名与二进制日志相同,扩展名为.index
二进制索引文件通过--log-bin-index[=file_name]选项来指定
RESETMASTER语句将删除所有二进制日志文件,这将影响到从库。也可以用PURGE MASTER LOGS只删除部分二进制文件。
3.二进制日志记录了所有对数据库执行更改的操作,二进制主要有以下两种作用:
1、恢复(recovery)2、复制(replication)
二进制日志的启动:配置参数log-bin[=name],如果不指定name,则默认二进制日志文件名为主机名,后缀名为二级制日志的序列号,所在路径为数据库所在目录。
以index为后缀的文件为二进制日志的索引文件,用来存储过程生产的二进制日志。
二进制日志相关的参数:
max_binlog_size、binlog_cache_size、sync_binlog、binlog-do-db、binlog-ignore-db、log-slave-update、binlog_format
(1)max_binlog_size:该参数指定了单个二进制日志文件的最大值,如果超过该值,则产生新的二进制日志文件,后缀名+1,并记录到.index文件,从Mysql5.0开始的默认值为1073741824,代表1G。
以MySQL5.5为例如下:
mysql> SHOW VARIABLES LIKE ‘%max_binlog%‘; +----------------------------+----------------------+ | Variable_name | Value | +----------------------------+----------------------+ | max_binlog_cache_size | 18446744073709547520 | | max_binlog_size | 1073741824 | | max_binlog_stmt_cache_size | 18446744073709547520 | +----------------------------+----------------------+ 3 rows in set (0.02 sec)
当使用事务的存储引擎InnoDB时,所有未提交的事务会记录到一个缓存中,等待事务提交时,直接将缓冲中的二进制日志写入二进制日志文件,而该缓冲的大小由binlog_cache_size决定,默认大小为32KB,此外,binlog_cache_size是基于session的,也就是,当一个线程开始一个事务时,mysql会自动分配一个大小为binlog_cache_size的缓存,因此该值得设置需要相当小心,可以通过show global status 查看binlog_cache_use、binlog_cache_disk_use的状态,可以判断当前binlog_cache_size的设置是否合适。
(2)Binlog_cache_size的默认大小为32KB。
mysql> SHOW VARIABLES LIKE ‘binlog_cache%‘; +-------------------+-------+ | Variable_name | Value | +-------------------+-------+ | binlog_cache_size | 32768 | +-------------------+-------+ 1 row in set (0.00 sec)
3、参数sync_binlog=[N]表示每写缓存多少次就同步到磁盘,如果将N设置为1,则表示采用同步写磁盘的方式来写二进制日志,该参数很重要,这个以后还会提到。值得注意的是,在将该参数设置为1时,也应该将innodb_support_xa设为1来解决,这可以确保二进制日志和InnoDB存储引擎数据文件的同步。
4、参数binlog-do-db和binlog-ignore-db表示需要写入或者忽略写入哪些库的日志,默认值为空,则表示将所有库的日志同步到二进制日志。
5、Log-slave-update该参数在搭建master=>slave=>slave的架构时,需要配置。
6、Binlog_format参数也特别重要。从mysql5.1版本开始引入这个参数,该参数可以设置的值有STATEMENT\、ROW、MIXED;
(1)STATEMENT格式和之前的mysql版本一样,二进制日志文件记录的是日志的逻辑SQL语句。
(2)在ROW格式下,二进制日志记录的不再是简单的SQL语句了,而是记录表的行更改情况,此时可以将InnoDB的事务隔离基本设为READ COMMITTED,以获得更好的并发性。
(3)MIXED格式下,mysql默认采用的STATEMENT格式进行二进制日志文件的记录,但是在一些情况下会使用ROW格式,可能的情况包括:
1)表的存储引擎为NDB,这时对于表的DML操作都会以ROW格式记录
2)使用了UUID()、USER()、CURRENT_USER()、FOUND_ROWS()、ROW_COUNT()等不确定函数
3)使用了INSERT DELAY语句
4)使用了用户定义函数
5)使用了临时表
实践案例应用:
(1).二进制日志存放位置
[[email protected] ~]# cat /etc/my.cnf | grep datadir datadir = /mydata/data
或:
mysql> SHOW VARIABLES LIKE ‘%datadir%‘; +---------------+---------------+ | Variable_name | Value | +---------------+---------------+ | datadir | /mydata/data/ | +---------------+---------------+ 1 row in set (0.08 sec)
查看日志信息:
[[email protected] ~]# ls -l /mydata/data/mysql-bin.* -rw-rw----. 1 mysql mysql 126 May 6 14:39 /mydata/data/mysql-bin.000001 -rw-rw----. 1 mysql mysql 2576 May 8 17:02 /mydata/data/mysql-bin.000002 -rw-rw----. 1 mysql mysql 126 May 8 17:03 /mydata/data/mysql-bin.000003 -rw-rw----. 1 mysql mysql 126 May 8 17:07 /mydata/data/mysql-bin.000004 -rw-rw----. 1 mysql mysql 126 May 8 17:08 /mydata/data/mysql-bin.000005 -rw-rw----. 1 mysql mysql 126 May 8 17:09 /mydata/data/mysql-bin.000006 -rw-rw----. 1 mysql mysql 22481 May 27 18:34 /mydata/data/mysql-bin.000007 -rw-rw----. 1 mysql mysql 107 Jun 4 10:48 /mydata/data/mysql-bin.000008 -rw-rw----. 1 mysql mysql 152 Jun 4 10:48 /mydata/data/mysql-bin.index
tips:mysql-bin.index记录MySQL的index文件
[[email protected] ~]# cat /mydata/data/mysql-bin.index ./mysql-bin.000001 ./mysql-bin.000002 ./mysql-bin.000003 ./mysql-bin.000004 ./mysql-bin.000005 ./mysql-bin.000006 ./mysql-bin.000007 ./mysql-bin.000008
(2).二进制日志文件的切换
执行flush logs产生新的二进制日志:
mysql> SHOW MASTER STATUS; --查看当前记录二进制日志文件 +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000008 | 107 | | | +------------------+----------+--------------+------------------+ 1 row in set (0.01 sec)
执行FLUSH LOGS滚动日志,生成新的日志文件
mysql> FLUSH LOGS; Query OK, 0 rows affected (0.08 sec)
查询滚动日志生成的文件
[[email protected] ~]# ls -l /mydata/data/mysql-bin.* -rw-rw----. 1 mysql mysql 126 May 6 14:39 /mydata/data/mysql-bin.000001 -rw-rw----. 1 mysql mysql 2576 May 8 17:02 /mydata/data/mysql-bin.000002 -rw-rw----. 1 mysql mysql 126 May 8 17:03 /mydata/data/mysql-bin.000003 -rw-rw----. 1 mysql mysql 126 May 8 17:07 /mydata/data/mysql-bin.000004 -rw-rw----. 1 mysql mysql 126 May 8 17:08 /mydata/data/mysql-bin.000005 -rw-rw----. 1 mysql mysql 126 May 8 17:09 /mydata/data/mysql-bin.000006 -rw-rw----. 1 mysql mysql 22481 May 27 18:34 /mydata/data/mysql-bin.000007 -rw-rw----. 1 mysql mysql 150 Jun 4 13:35 /mydata/data/mysql-bin.000008 -->>滚动前日志文件 -rw-rw----. 1 mysql mysql 107 Jun 4 13:35 /mydata/data/mysql-bin.000009 -->>滚动后日志文件 -rw-rw----. 1 mysql mysql 171 Jun 4 13:35 /mydata/data/mysql-bin.index
查询当前日志文件记录状态及日志文件
mysql> SHOW MASTER STATUS; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000009 | 107 | | | +------------------+----------+--------------+------------------+ 1 row in set (0.00 sec)
可以看到日志文件已经变成mysql-bin.000009了,证明已经滚动成功了。
Shell模式使用mysqladmin
[[email protected] ~]# mysqladmin flush-logs -uroot -predhat [[email protected] ~]# ls -l /mydata/data/mysql-bin.* -rw-rw----. 1 mysql mysql 126 May 6 14:39 /mydata/data/mysql-bin.000001 -rw-rw----. 1 mysql mysql 2576 May 8 17:02 /mydata/data/mysql-bin.000002 -rw-rw----. 1 mysql mysql 126 May 8 17:03 /mydata/data/mysql-bin.000003 -rw-rw----. 1 mysql mysql 126 May 8 17:07 /mydata/data/mysql-bin.000004 -rw-rw----. 1 mysql mysql 126 May 8 17:08 /mydata/data/mysql-bin.000005 -rw-rw----. 1 mysql mysql 126 May 8 17:09 /mydata/data/mysql-bin.000006 -rw-rw----. 1 mysql mysql 22481 May 27 18:34 /mydata/data/mysql-bin.000007 -rw-rw----. 1 mysql mysql 150 Jun 4 13:35 /mydata/data/mysql-bin.000008 -rw-rw----. 1 mysql mysql 150 Jun 4 13:55 /mydata/data/mysql-bin.000009 -rw-rw----. 1 mysql mysql 107 Jun 4 13:55 /mydata/data/mysql-bin.000010 -rw-rw----. 1 mysql mysql 190 Jun 4 13:55 /mydata/data/mysql-bin.index
查询当前日志文件记录状态及日志文件
mysql> SHOW MASTER STATUS; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000010 | 107 | | | +------------------+----------+--------------+------------------+ 1 row in set (0.00 sec)
[[email protected] ~]# mysqladmin refresh -uroot -predhat [[email protected] ~]# ls -l /mydata/data/mysql-bin.* -rw-rw----. 1 mysql mysql 126 May 6 14:39 /mydata/data/mysql-bin.000001 -rw-rw----. 1 mysql mysql 2576 May 8 17:02 /mydata/data/mysql-bin.000002 -rw-rw----. 1 mysql mysql 126 May 8 17:03 /mydata/data/mysql-bin.000003 -rw-rw----. 1 mysql mysql 126 May 8 17:07 /mydata/data/mysql-bin.000004 -rw-rw----. 1 mysql mysql 126 May 8 17:08 /mydata/data/mysql-bin.000005 -rw-rw----. 1 mysql mysql 126 May 8 17:09 /mydata/data/mysql-bin.000006 -rw-rw----. 1 mysql mysql 22481 May 27 18:34 /mydata/data/mysql-bin.000007 -rw-rw----. 1 mysql mysql 150 Jun 4 13:35 /mydata/data/mysql-bin.000008 -rw-rw----. 1 mysql mysql 150 Jun 4 13:55 /mydata/data/mysql-bin.000009 -rw-rw----. 1 mysql mysql 150 Jun 4 13:58 /mydata/data/mysql-bin.000010 -rw-rw----. 1 mysql mysql 107 Jun 4 13:58 /mydata/data/mysql-bin.000011 -rw-rw----. 1 mysql mysql 209 Jun 4 13:58 /mydata/data/mysql-bin.index
查询当前日志文件记录状态及日志文件
mysql> SHOW MASTER STATUS; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000011 | 107 | | | +------------------+----------+--------------+------------------+ 1 row in set (0.01 sec)
(3)查询与日志相关的参数
mysql> SHOW VARIABLES LIKE ‘%log%‘; +-----------------------------------------+-----------------------------------+ | Variable_name | Value | +-----------------------------------------+-----------------------------------+ | back_log | 50 | | binlog_cache_size | 32768 | | binlog_direct_non_transactional_updates | OFF | | binlog_format | MIXED | | binlog_stmt_cache_size | 32768 | | expire_logs_days | 0 | | general_log | OFF | | general_log_file | /mydata/data/mysql.log | | innodb_flush_log_at_trx_commit | 1 | | innodb_locks_unsafe_for_binlog | OFF | | innodb_log_buffer_size | 8388608 | | innodb_log_file_size | 5242880 | | innodb_log_files_in_group | 2 | | innodb_log_group_home_dir | ./ | | innodb_mirrored_log_groups | 1 | | log | OFF | | log_bin | ON ----->>开启二进制日志功能 | | log_bin_trust_function_creators | OFF | | log_error | /mydata/data/mysql.samlee.com.err | | log_output | FILE | | log_queries_not_using_indexes | OFF | | log_slave_updates | OFF | | log_slow_queries | OFF | | log_warnings | 1 | | max_binlog_cache_size | 18446744073709547520 | | max_binlog_size | 1073741824 | | max_binlog_stmt_cache_size | 18446744073709547520 | | max_relay_log_size | 0 | | relay_log | | | relay_log_index | | | relay_log_info_file | relay-log.info | | relay_log_purge | ON | | relay_log_recovery | OFF | | relay_log_space_limit | 0 | | slow_query_log | OFF | | slow_query_log_file | /mydata/data/mysql-slow.log | | sql_log_bin | ON | | sql_log_off | OFF | | sync_binlog | 0 | | sync_relay_log | 0 | | sync_relay_log_info | 0 | +-----------------------------------------+-----------------------------------+ 41 rows in set (0.01 sec)
(4)事务操作生成二进制日志
mysql> USE hellodb; Database changed mysql> SHOW TABLES; +-------------------+ | Tables_in_hellodb | +-------------------+ | classes | | coc | | courses | | scores | | students | | teachers | | toc | +-------------------+ 7 rows in set (0.00 sec) mysql> SELECT * FROM coc; +----+---------+----------+ | ID | ClassID | CourseID | +----+---------+----------+ | 1 | 1 | 2 | | 2 | 1 | 5 | | 3 | 2 | 2 | | 4 | 2 | 6 | | 5 | 3 | 1 | | 6 | 3 | 7 | | 7 | 4 | 5 | | 8 | 4 | 2 | | 9 | 5 | 1 | | 10 | 5 | 9 | | 11 | 6 | 3 | | 12 | 6 | 4 | | 13 | 7 | 4 | | 14 | 7 | 3 | +----+---------+----------+ 14 rows in set (0.02 sec) mysql> INSERT INTO coc VALUES (15,7,5); Query OK, 1 row affected (0.00 sec) mysql> COMMIT; Query OK, 0 rows affected (0.00 sec)
查询当前使用的二进制日志文件
mysql> SHOW MASTER STATUS; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000011 | 347 | | | +------------------+----------+--------------+------------------+ 1 row in set (0.00 sec)
查询生成的二进制日志内容:
[[email protected] ~]# mysqlbinlog /mydata/data/mysql-bin.000011 /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/; /*!40019 SET @@session.max_insert_delayed_threads=0*/; /*!50003 SET @[email protected]@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; # at 4 #160604 13:58:31 server id 1 end_log_pos 107 Start: binlog v 4, server v 5.5.33-log created 160604 13:58:31 # Warning: this binlog is either in use or was not closed properly. BINLOG ‘ B25SVw8BAAAAZwAAAGsAAAABAAQANS41LjMzLWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAEzgNAAgAEgAEBAQEEgAAVAAEGggAAAAICAgCAA== ‘/*!*/; # at 107 #160604 14:14:44 server id 1 end_log_pos 178 Query thread_id=10 exec_time=0 error_code=0 SET TIMESTAMP=1465020884/*!*/; SET @@session.pseudo_thread_id=10/*!*/; SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/; SET @@session.sql_mode=0/*!*/; 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=33/*!*/; SET @@session.lc_time_names=0/*!*/; SET @@session.collation_database=DEFAULT/*!*/; BEGIN /*!*/; # at 178 #160604 14:14:44 server id 1 end_log_pos 275 Query thread_id=10 exec_time=0 error_code=0 use `hellodb`/*!*/; SET TIMESTAMP=1465020884/*!*/; INSERT INTO coc VALUES (15,7,5) /*!*/; # at 275 #160604 14:14:44 server id 1 end_log_pos 347 Query thread_id=10 exec_time=0 error_code=0 SET TIMESTAMP=1465020884/*!*/; COMMIT /*!*/; DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; /*!50003 SET [email protected]_COMPLETION_TYPE*/; /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
[[email protected] ~]# strings /mydata/data/mysql-bin.000011 5.5.33-log hellodb BEGIN hellodb INSERT INTO coc VALUES (15,7,5) hellodb COMMIT
查看生成的二进制日志
mysql> SHOW BINARY LOGS; +------------------+-----------+ | Log_name | File_size | +------------------+-----------+ | mysql-bin.000001 | 126 | | mysql-bin.000002 | 2576 | | mysql-bin.000003 | 126 | | mysql-bin.000004 | 126 | | mysql-bin.000005 | 126 | | mysql-bin.000006 | 126 | | mysql-bin.000007 | 22481 | | mysql-bin.000008 | 150 | | mysql-bin.000009 | 150 | | mysql-bin.000010 | 150 | | mysql-bin.000011 | 347 | +------------------+-----------+ 11 rows in set (0.00 sec)
查看日志记录的事件:
mysql> SHOW BINLOG EVENTS; +------------------+-----+-------------+-----------+-------------+---------------------------------------+ | Log_name | Pos | Event_type | Server_id | End_log_pos | Info | +------------------+-----+-------------+-----------+-------------+---------------------------------------+ | mysql-bin.000001 | 4 | Format_desc | 1 | 107 | Server ver: 5.5.33-log, Binlog ver: 4 | | mysql-bin.000001 | 107 | Stop | 1 | 126 | | +------------------+-----+-------------+-----------+-------------+---------------------------------------+ 2 rows in set (0.02 sec) mysql> SHOW BINLOG EVENTS IN ‘mysql-bin.000011‘; +------------------+-----+-------------+-----------+-------------+------------------------------------------------+ | Log_name | Pos | Event_type | Server_id | End_log_pos | Info | +------------------+-----+-------------+-----------+-------------+------------------------------------------------+ | mysql-bin.000011 | 4 | Format_desc | 1 | 107 | Server ver: 5.5.33-log, Binlog ver: 4 | | mysql-bin.000011 | 107 | Query | 1 | 178 | BEGIN | | mysql-bin.000011 | 178 | Query | 1 | 275 | use `hellodb`; INSERT INTO coc VALUES (15,7,5) | | mysql-bin.000011 | 275 | Query | 1 | 347 | COMMIT | +------------------+-----+-------------+-----------+-------------+------------------------------------------------+ 4 rows in set (0.00 sec)
使用二进制日志进行数据恢复应用
模拟数据环境
mysql> USE hellodb; Database changed mysql> SELECT * FROM coc; +----+---------+----------+ | ID | ClassID | CourseID | +----+---------+----------+ | 15 | 7 | 5 | +----+---------+----------+ 1 rows in set (0.00 sec) mysql> DELETE FROM coc; Query OK, 1 rows affected (0.01 sec) mysql> COMMIT; Query OK, 0 rows affected (0.00 sec) mysql> SELECT * FROM coc; Empty set (0.00 sec)
利用日志恢复,将日志生成文件进行分析:
[[email protected] ~]# mysqlbinlog /mydata/data/mysql-bin.000011 > /tmp/log11.txt
[[email protected] ~]# cat /tmp/log11.txt
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_T[email protected]@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#160604 13:58:31 server id 1 end_log_pos 107 Start: binlog v 4, server v 5.5.33-log created 160604 13:58:31
# Warning: this binlog is either in use or was not closed properly.
BINLOG ‘
B25SVw8BAAAAZwAAAGsAAAABAAQANS41LjMzLWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAEzgNAAgAEgAEBAQEEgAAVAAEGggAAAAICAgCAA==
‘/*!*/;
# at 107
#160604 14:14:44 server id 1 end_log_pos 178 Query thread_id=10 exec_time=0 error_code=0
SET TIMESTAMP=1465020884/*!*/;
SET @@session.pseudo_thread_id=10/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=0/*!*/;
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=33/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
BEGIN
/*!*/;
# at 178
#160604 14:14:44 server id 1 end_log_pos 275 Query thread_id=10 exec_time=0 error_code=0
use `hellodb`/*!*/;
SET TIMESTAMP=1465020884/*!*/;
INSERT INTO coc VALUES (15,7,5)
/*!*/;
# at 275
#160604 14:14:44 server id 1 end_log_pos 347 Query thread_id=10 exec_time=0 error_code=0
SET TIMESTAMP=1465020884/*!*/;
COMMIT
/*!*/;
# at 347
#160604 15:31:40 server id 1 end_log_pos 418 Query thread_id=10 exec_time=0 error_code=0
SET TIMESTAMP=1465025500/*!*/;
BEGIN
/*!*/;
# at 418 ;;日志记录的操作事件的编号,如果要恢复前面的数据,需要在DELETE前停止
#160604 15:31:40 server id 1 end_log_pos 499 Query thread_id=10 exec_time=0 error_code=0
SET TIMESTAMP=1465025500/*!*/;
DELETE FROM coc
/*!*/;
# at 499
#160604 15:31:40 server id 1 end_log_pos 571 Query thread_id=10 exec_time=0 error_code=0
SET TIMESTAMP=1465025500/*!*/;
COMMIT
/*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET [email protected]_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
利用二进制日志恢复
[[email protected] ~]# mysqlbinlog /mydata/data/mysql-bin.000011 | mysql -uroot -predhat
查看已恢复的数据
mysql> SELECT * FROM coc; +----+---------+----------+ | ID | ClassID | CourseID | +----+---------+----------+ | 15 | 7 | 5 | +----+---------+----------+ 1 row in set (0.00 sec)
本文出自 “Opensamlee” 博客,请务必保留此出处http://gzsamlee.blog.51cto.com/9976612/1786095
以上是关于关系型数据库之Mysql二进制日志管理的主要内容,如果未能解决你的问题,请参考以下文章