当前位置:网站首页>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"
边栏推荐
- Redis之核心配置
- 数字人主播618手语带货,便捷2780万名听障人士
- LeetCode:387. The first unique character in the string
- 多元聚类分析
- LeetCode:498. Diagonal traversal
- LeetCode41——First Missing Positive——hashing in place & swap
- 不同的数据驱动代码执行相同的测试场景
- Blue Bridge Cup_ Single chip microcomputer_ PWM output
- LeetCode:214. Shortest palindrome string
- Pytorch view tensor memory size
猜你喜欢
[OC]-<UI入门>--常用控件-UIButton
What is MySQL? What is the learning path of MySQL
SAP ui5 date type sap ui. model. type. Analysis of the parsing format of date
如何正确截取字符串(例:应用报错信息截取入库操作)
CUDA realizes focal_ loss
【图的三大存储方式】只会用邻接矩阵就out了
Intel distiller Toolkit - Quantitative implementation 2
UML diagram memory skills
Reids之缓存预热、雪崩、穿透
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
随机推荐
Intel distiller Toolkit - Quantitative implementation 3
Go redis initialization connection
[OC-Foundation框架]--<Copy对象复制>
Detailed explanation of dynamic planning
Different data-driven code executes the same test scenario
Le modèle sentinelle de redis
LeetCode:26. Remove duplicates from an ordered array
[OC]-<UI入门>--常用控件的学习
LeetCode:236. The nearest common ancestor of binary tree
Intel Distiller工具包-量化实现3
[shell script] - archive file script
Redis cluster
SimCLR:NLP中的对比学习
ant-design的走马灯(Carousel)组件在TS(typescript)环境中调用prev以及next方法
What is MySQL? What is the learning path of MySQL
Redis之Geospatial
Kratos战神微服务框架(二)
Kratos ares microservice framework (II)
Show slave status \ read in G_ Master_ Log_ POS and relay_ Log_ The (size) relationship of POS
自定义卷积注意力算子的CUDA实现