当前位置:网站首页>Mysql database recovery (using mysqlbinlog command)
Mysql database recovery (using mysqlbinlog command)
2022-07-06 09:15:00 【wx5caecf2ed0645】
1: Turn on binlog logging
modify mysql The configuration file mysql.ini, stay [mysqld] Add under node
Copy code The code is as follows :
# log-bin
log-bin = E:/log/logbin.log
Do not include Chinese and spaces in the path . restart mysql service . Stop and start... From the command line mysql service
Copy code The code is as follows :
c:\>net stop mysql;
c:\>net start mysql;
Enter the command line mysql And check whether the binary log has been started
Sql Code
Copy code The code is as follows :
mysql>show variables like 'log_%';
After the log is successfully opened , Will be in E:/log/ Create under directory logbin.index and logbin.000001 Two documents .logbin.000001 Is the backup file of the database , You can restore the database through this file later .
2: View the backed up binaries
Sql Code
Copy code The code is as follows :
c:\mysql\bin\>mysqlbinlog e:/log/logbin.000001
There are many operations recorded in the future , The command line method is basically useless . You can view the log content by exporting the log to a file
2.1 export
Xml Code
Copy code The code is as follows :
c:\mysql\bin\>mysqlbinlog e:/log/logbin.000001 > e:/log/log.txt
">": Import into file ; ">>": Append to file
If there are multiple log files
Sql Code
Copy code The code is as follows :
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 Export according to the specified location :
Sql Code
Copy code The code is as follows :
c:\mysql\bin\>mysqlbinlog --start-position=185 --stop-position=338 e:/log/logbin.000001 > e:/log/log3.txt
2.3 Export according to the specified time :
Xml Code
Copy code The code is as follows :
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: Restore database from backup
Did an update operation , After that, the contents of the log are as follows :
Sql Code
Copy code The code is as follows :
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @[email protected]@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 [email protected]_COMPLETION_TYPE*/;
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @[email protected]@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 [email protected]_COMPLETION_TYPE*/;
3.1 recovery :
Sql Code
Copy code The code is as follows :
c:\mysql\bin\>mysqlbinlog e:/log/logbin.000001 | mysql -u root -p
3.2 Restore according to the specified location :
Sql Code
Copy code The code is as follows :
c:\mysql\bin\>mysqlbinlog --start-position=185 --stop-position=338 e:/log/logbin.000001 | mysql -u root -p
3.3 Recover at a specified time :
Xml Code
Copy code The code is as follows :
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 Recover from the exported script file
Sql Code
Copy code The code is as follows :
c:\mysql\bin\>mysql -e "source e:/log/log.sql"
4. Other common operations
4.1 View all log files
Sql Code
Copy code The code is as follows :
mysql>show master logs;
4.2 Currently in use binlog file
Sql Code
Copy code The code is as follows :
mysql>show binlog events \g;
4.3 Produce a new binlog Log files
Sql Code
Copy code The code is as follows :
mysql>flush logs;
4.4 Delete all binary logs , And start recording again ( Be careful :reset master The command will delete all binary logs )
Sql Code
Copy code The code is as follows :
mysql > flush logs;
mysql > reset master;
4.5 Quickly back up data to sql file
Sql Code
Copy code The code is as follows :
c:\mysql\bin>mysqldump -u root -p --opt --quick interactive > e:/log/mysqldump.sql
For easy viewing , Write the command recovered from the script once
Sql Code
Copy code The code is as follows :
c:\mysql\bin\>mysql -e "source e:/log/mysqldump.sql"
边栏推荐
- LeetCode:34. Find the first and last positions of elements in a sorted array
- [OC-Foundation框架]--<Copy对象复制>
- opencv+dlib实现给蒙娜丽莎“配”眼镜
- Advance Computer Network Review(1)——FatTree
- Redis cluster
- QDialog
- Pytest parameterization some tips you don't know / pytest you don't know
- 【图的三大存储方式】只会用邻接矩阵就out了
- xargs命令的基本用法
- [OC]-<UI入门>--常用控件-提示对话框 And 等待提示器(圈)
猜你喜欢
Mongodb installation and basic operation
[text generation] recommended in the collection of papers - Stanford researchers introduce time control methods to make long text generation more smooth
Redis之Geospatial
Booking of tourism products in Gansu quadrupled: "green horse" became popular, and one room of B & B around Gansu museum was hard to find
Nacos 的安装与服务的注册
BN折叠及其量化
[oc]- < getting started with UI> -- common controls uibutton
LeetCode:124. Maximum path sum in binary tree
[three storage methods of graph] just use adjacency matrix to go out
注意力机制的一种卷积替代方式
随机推荐
Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges
Leetcode: Jianzhi offer 03 Duplicate numbers in array
一改测试步骤代码就全写 为什么不试试用 Yaml实现数据驱动?
Kratos ares microservice framework (II)
Parameterization of postman
Digital people anchor 618 sign language with goods, convenient for 27.8 million people with hearing impairment
Reids之删除策略
Redis之哨兵模式
Advanced Computer Network Review(5)——COPE
SAP ui5 date type sap ui. model. type. Analysis of the parsing format of date
【每日一题】搬运工 (DFS / DP)
[OC-Foundation框架]-<字符串And日期与时间>
BN folding and its quantification
Advance Computer Network Review(1)——FatTree
Li Kou daily question 1 (2)
Ijcai2022 collection of papers (continuously updated)
postman之参数化详解
After reading the programmer's story, I can't help covering my chest...
BMINF的後訓練量化實現
go-redis之初始化連接