您好,登錄后才能下訂單哦!
下文主要給大家?guī)?a title="關(guān)系型數(shù)據(jù)庫" target="_blank" href="http://kemok4.com/mysql/">關(guān)系型數(shù)據(jù)庫的管理Mysql二進制日志詳細步驟,希望這些內(nèi)容能夠帶給大家實際用處,這也是我編輯關(guān)系型數(shù)據(jù)庫的管理Mysql二進制日志詳細步驟這篇文章的主要目的。好了,廢話不多說,大家直接看下文吧。
MySQL二進制日志(Binary Log)
1.它包含的內(nèi)容及作用如下:
包含了所有更新了數(shù)據(jù)或者已經(jīng)潛在更新了數(shù)據(jù)(比如沒有匹配任何行的一個DELETE)
包含關(guān)于每個更新數(shù)據(jù)庫(DML)的語句的執(zhí)行時間信息
不包含沒有修改任何數(shù)據(jù)的語句,如果需要啟用該選項,需要開啟通用日志功能
主要目的是盡可能的將數(shù)據(jù)庫恢復到數(shù)據(jù)庫故障點,因為二進制日志包含備份后進行的所有更新
用于在主復制云服務器上記錄所有將發(fā)送給從云服務器的語句
啟用該選項數(shù)據(jù)庫性能降低1%,但保障數(shù)據(jù)庫完整性,對于重要數(shù)據(jù)庫值得以性能換完整。有些類似于Oracle開啟歸檔模式。
2.開啟二進制日志的方法及屬性
使用--log-bin[=file_name]選項或在配置文件中指定log-bin啟動時,mysqld寫入包含所有更新數(shù)據(jù)的SQL命令的日志文件。
對于未給出file_name值,默認名為-bin后面所跟的主機名。
在未指定絕對路徑的情形下,缺省位置保存在數(shù)據(jù)目錄下。
每個二進制日志名會添加一個數(shù)字擴展名用于日志老化,因此不支持自定義的擴展名,會被mysql數(shù)字擴展名動態(tài)替換。
若當前的日志大小達到max_binlog_size,則自動創(chuàng)建新的二進制日志。
對于大的事務,二進制日志會超過max_binlog_size設(shè)定的值。也即是事務僅僅寫入一個二進制日志。
由是可知,二進制日志文件大小接近,其size不是完全相等,這點不同于oracle。
二進制日志文件會有一個對應二進制日志索引文件,該文件包含所有的二進制日志,其文件名與二進制日志相同,擴展名為.index
二進制索引文件通過--log-bin-index[=file_name]選項來指定
RESETMASTER語句將刪除所有二進制日志文件,這將影響到從庫。也可以用PURGE MASTER LOGS只刪除部分二進制文件。
3.二進制日志記錄了所有對數(shù)據(jù)庫執(zhí)行更改的操作,二進制主要有以下兩種作用:
1、恢復(recovery)2、復制(replication)
二進制日志的啟動:配置參數(shù)log-bin[=name],如果不指定name,則默認二進制日志文件名為主機名,后綴名為二級制日志的序列號,所在路徑為數(shù)據(jù)庫所在目錄。
以index為后綴的文件為二進制日志的索引文件,用來存儲過程生產(chǎn)的二進制日志。
二進制日志相關(guān)的參數(shù):
max_binlog_size、binlog_cache_size、sync_binlog、binlog-do-db、binlog-ignore-db、log-slave-update、binlog_format
(1)max_binlog_size:該參數(shù)指定了單個二進制日志文件的最大值,如果超過該值,則產(chǎn)生新的二進制日志文件,后綴名+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的緩存,因此該值得設(shè)置需要相當小心,可以通過show global status 查看binlog_cache_use、binlog_cache_disk_use的狀態(tài),可以判斷當前binlog_cache_size的設(shè)置是否合適。
(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、參數(shù)sync_binlog=[N]表示每寫緩存多少次就同步到磁盤,如果將N設(shè)置為1,則表示采用同步寫磁盤的方式來寫二進制日志,該參數(shù)很重要,這個以后還會提到。值得注意的是,在將該參數(shù)設(shè)置為1時,也應該將innodb_support_xa設(shè)為1來解決,這可以確保二進制日志和InnoDB存儲引擎數(shù)據(jù)文件的同步。
4、參數(shù)binlog-do-db和binlog-ignore-db表示需要寫入或者忽略寫入哪些庫的日志,默認值為空,則表示將所有庫的日志同步到二進制日志。
5、Log-slave-update該參數(shù)在搭建master=>slave=>slave的架構(gòu)時,需要配置。
6、Binlog_format參數(shù)也特別重要。從mysql5.1版本開始引入這個參數(shù),該參數(shù)可以設(shè)置的值有STATEMENT\、ROW、MIXED;
(1)STATEMENT格式和之前的mysql版本一樣,二進制日志文件記錄的是日志的邏輯SQL語句。
(2)在ROW格式下,二進制日志記錄的不再是簡單的SQL語句了,而是記錄表的行更改情況,此時可以將InnoDB的事務隔離基本設(shè)為READ COMMITTED,以獲得更好的并發(fā)性。
(3)MIXED格式下,mysql默認采用的STATEMENT格式進行二進制日志文件的記錄,但是在一些情況下會使用ROW格式,可能的情況包括:
1)表的存儲引擎為NDB,這時對于表的DML操作都會以ROW格式記錄
2)使用了UUID()、USER()、CURRENT_USER()、FOUND_ROWS()、ROW_COUNT()等不確定函數(shù)
3)使用了INSERT DELAY語句
4)使用了用戶定義函數(shù)
5)使用了臨時表
實踐案例應用:
(1).二進制日志存放位置
[root@mysql ~]# 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)
查看日志信息:
[root@mysql ~]# 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文件
[root@mysql ~]# 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).二進制日志文件的切換
執(zhí)行flush logs產(chǎn)生新的二進制日志:
mysql> SHOW MASTER STATUS; --查看當前記錄二進制日志文件 +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000008 | 107 | | | +------------------+----------+--------------+------------------+ 1 row in set (0.01 sec)
執(zhí)行FLUSH LOGS滾動日志,生成新的日志文件
mysql> FLUSH LOGS; Query OK, 0 rows affected (0.08 sec)
查詢滾動日志生成的文件
[root@mysql ~]# 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
查詢當前日志文件記錄狀態(tài)及日志文件
mysql> SHOW MASTER STATUS; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000009 | 107 | | | +------------------+----------+--------------+------------------+ 1 row in set (0.00 sec)
可以看到日志文件已經(jīng)變成mysql-bin.000009了,證明已經(jīng)滾動成功了。
Shell模式使用mysqladmin
[root@mysql ~]# mysqladmin flush-logs -uroot -predhat [root@mysql ~]# 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
查詢當前日志文件記錄狀態(tài)及日志文件
mysql> SHOW MASTER STATUS; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000010 | 107 | | | +------------------+----------+--------------+------------------+ 1 row in set (0.00 sec)
[root@mysql ~]# mysqladmin refresh -uroot -predhat [root@mysql ~]# 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
查詢當前日志文件記錄狀態(tài)及日志文件
mysql> SHOW MASTER STATUS; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000011 | 107 | | | +------------------+----------+--------------+------------------+ 1 row in set (0.01 sec)
(3)查詢與日志相關(guān)的參數(shù)
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)
查詢生成的二進制日志內(nèi)容:
[root@mysql ~]# mysqlbinlog /mydata/data/mysql-bin.000011 /*!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 #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 COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
[root@mysql ~]# 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)
使用二進制日志進行數(shù)據(jù)恢復應用
模擬數(shù)據(jù)環(huán)境
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)
利用日志恢復,將日志生成文件進行分析:
[root@mysql ~]# mysqlbinlog /mydata/data/mysql-bin.000011 > /tmp/log11.txt
[root@mysql ~]# cat /tmp/log11.txt
/*!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
#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 ;;日志記錄的操作事件的編號,如果要恢復前面的數(shù)據(jù),需要在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 COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
利用二進制日志恢復
[root@mysql ~]# mysqlbinlog /mydata/data/mysql-bin.000011 | mysql -uroot -predhat
查看已恢復的數(shù)據(jù)
mysql> SELECT * FROM coc; +----+---------+----------+ | ID | ClassID | CourseID | +----+---------+----------+ | 15 | 7 | 5 | +----+---------+----------+ 1 row in set (0.00 sec)
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。