程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> MySQL數據庫恢復(應用mysqlbinlog敕令)

MySQL數據庫恢復(應用mysqlbinlog敕令)

編輯:MySQL綜合教程

MySQL數據庫恢復(應用mysqlbinlog敕令)。本站提示廣大學習愛好者:(MySQL數據庫恢復(應用mysqlbinlog敕令))文章只能為提供參考,不一定能成為您想要的結果。以下是MySQL數據庫恢復(應用mysqlbinlog敕令)正文


1:開啟binlog日記記載
修正mysql設置裝備擺設文件mysql.ini,在[mysqld]節點下添加

# log-bin
log-bin = E:/log/logbin.log

途徑中不要包括中文和空格。重啟mysql辦事。經由過程敕令行停滯和啟動mysql辦事

c:\>net stop mysql;
c:\>net start mysql;

進入敕令行進入mysql並檢查二進制日記能否曾經啟動
Sql代碼

mysql>show variables like 'log_%';

日記勝利開啟後,會在E:/log/目次下創立logbin.index和logbin.000001兩個文件。logbin.000001就是數據庫的備份文件,今後便可以經由過程此文件對數據庫停止恢復操作。

2:檢查備份的二進制文件
Sql代碼

c:\mysql\bin\>mysqlbinlog e:/log/logbin.000001

往後記載的操作多了,敕令行方法根本就用不上了。可使用將日記導出文件的方法來檢查日記內容
2.1 導出
Xml代碼

c:\mysql\bin\>mysqlbinlog e:/log/logbin.000001 > e:/log/log.txt

">": 導入到文件中; ">>": 追加到文件中
假如有多個日記文件
Sql代碼

c:\mysql\bin\> mysqlbinlog e:/log/logbin.000001 > e:/log/log.sql
c:\mysql\bin\> mysqlbinlog e:/log/logbin.000002 >> e:/log/log.sq

2.2 按指定地位導出:
Sql代碼

c:\mysql\bin\>mysqlbinlog --start-position=185 --stop-position=338 e:/log/logbin.000001 > e:/log/log3.txt

2.3 按指准時間導出:
Xml代碼

c:\mysql\bin\>mysqlbinlog --start-datetime="2010-01-07 11:25:56" --stop-datetime="2010-01-07 13:23:50" e:/log/logbin.000001 > e:/log/log_by_date22.txt

3:從備份恢單數據庫
做了一次更新操作,以後日記的內容以下:
Sql代碼

/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#110107 13:23:50 server id 1 end_log_pos 106 Start: binlog v 4, server v 5.1.53-community-log created 110107 13:23:50 at startup
# Warning: this binlog is either in use or was not closed properly.
ROLLBACK/*!*/;
BINLOG '
ZqMmTQ8BAAAAZgAAAGoAAAABAAQANS4xLjUzLWNvbW11bml0eS1sb2cAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAABmoyZNEzgNAAgAEgAEBAQEEgAAUwAEGggAAAAICAgC
'/*!*/;
# at 106
#110107 13:26:58 server id 1 end_log_pos 185 Query thread_id=44 exec_time=1 error_code=0
SET TIMESTAMP=1294378018/*!*/;
SET @@session.pseudo_thread_id=44/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=1, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=1344274432/*!*/;
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 185
#110107 13:26:58 server id 1 end_log_pos 338 Query thread_id=44 exec_time=1 error_code=0
use ncl-interactive/*!*/;
SET TIMESTAMP=1294378018/*!*/;
UPDATE `t_system_id` SET `id_value`='3000' WHERE (`table_name`='t_working_day')
/*!*/;
# at 338
#110107 13:26:58 server id 1 end_log_pos 365 Xid = 8016
COMMIT/*!*/;
DELIMITER ;
DELIMITER /*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#110107 13:23:50 server id 1 end_log_pos 106 Start: binlog v 4, server v 5.1.53-community-log created 110107 13:23:50 at startup
# Warning: this binlog is either in use or was not closed properly.
ROLLBACK/*!*/;
BINLOG '
ZqMmTQ8BAAAAZgAAAGoAAAABAAQANS4xLjUzLWNvbW11bml0eS1sb2cAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAABmoyZNEzgNAAgAEgAEBAQEEgAAUwAEGggAAAAICAgC
'/*!*/;
# at 106
#110107 13:26:58 server id 1 end_log_pos 185 Query thread_id=44 exec_time=1 error_code=0
SET TIMESTAMP=1294378018/*!*/;
SET @@session.pseudo_thread_id=44/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=1, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=1344274432/*!*/;
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 185
#110107 13:26:58 server id 1 end_log_pos 338 Query thread_id=44 exec_time=1 error_code=0
use ncl-interactive/*!*/;
SET TIMESTAMP=1294378018/*!*/;
UPDATE `t_system_id` SET `id_value`='3000' WHERE (`table_name`='t_working_day')
/*!*/;
# at 338
#110107 13:26:58 server id 1 end_log_pos 365 Xid = 8016
COMMIT/*!*/;
DELIMITER ;
DELIMITER /*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;

3.1 恢復:
Sql代碼

c:\mysql\bin\>mysqlbinlog e:/log/logbin.000001 | mysql -u root -p

3.2 按指定地位恢復:
Sql代碼

c:\mysql\bin\>mysqlbinlog --start-position=185 --stop-position=338 e:/log/logbin.000001 | mysql -u root -p

3.3 按指准時間恢復:
Xml代碼

c:\mysql\bin\>mysqlbinlog --start-datetime="2010-01-07 11:25:56" --stop-datetime="2010-01-07 13:23:50" e:/log/logbin.000001 | mysql -u root -p

3.4 經由過程導出的劇本文件恢復
Sql代碼

c:\mysql\bin\>mysql -e "source e:/log/log.sql"

4.其他經常使用操作
4.1 檢查一切日記文件

Sql代碼

mysql>show master logs;

4.2 以後應用的binlog文件
Sql代碼

mysql>show binlog events \g;

4.3 發生一個新的binlog日記文件
Sql代碼

mysql>flush logs;

4.4 刪除一切二進制日記,並重新開端記載(留意:reset master敕令會刪除一切的二進制日記)
Sql代碼

mysql > flush logs;
mysql > reset master;

4.5 疾速備份數據到sql文件

Sql代碼

c:\mysql\bin>mysqldump -u root -p --opt --quick interactive > e:/log/mysqldump.sql

為了便利檢查,把從劇本恢復的敕令在寫一次
Sql代碼

c:\mysql\bin\>mysql -e "source e:/log/mysqldump.sql"
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved