当前位置:网站首页>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"
边栏推荐
- [OC foundation framework] - string and date and time >
- Digital people anchor 618 sign language with goods, convenient for 27.8 million people with hearing impairment
- Sentinel mode of redis
- LeetCode:221. Largest Square
- 【shell脚本】——归档文件脚本
- What is MySQL? What is the learning path of MySQL
- Redis之发布订阅
- The carousel component of ant design calls prev and next methods in TS (typescript) environment
- 数字人主播618手语带货,便捷2780万名听障人士
- [OC-Foundation框架]-<字符串And日期与时间>
猜你喜欢
Redis之cluster集群
Redis之Geospatial
requests的深入刨析及封装调用
Different data-driven code executes the same test scenario
Reids之删除策略
[today in history] February 13: the father of transistors was born The 20th anniversary of net; Agile software development manifesto was born
Ijcai2022 collection of papers (continuously updated)
BMINF的后训练量化实现
如何正确截取字符串(例:应用报错信息截取入库操作)
数字人主播618手语带货,便捷2780万名听障人士
随机推荐
多元聚类分析
LeetCode:673. Number of longest increasing subsequences
Compétences en mémoire des graphiques UML
UML diagram memory skills
七层网络体系结构
Mongodb installation and basic operation
Redis之主从复制
Implement window blocking on QWidget
Mathematical modeling 2004b question (transmission problem)
A convolution substitution of attention mechanism
Mise en œuvre de la quantification post - formation du bminf
【文本生成】论文合集推荐丨 斯坦福研究者引入时间控制方法 长文本生成更流畅
QML type: locale, date
Ijcai2022 collection of papers (continuously updated)
Kratos战神微服务框架(一)
[oc]- < getting started with UI> -- common controls uibutton
Pytorch view tensor memory size
KDD 2022 paper collection (under continuous update)
数学建模2004B题(输电问题)
ant-design的走马灯(Carousel)组件在TS(typescript)环境中调用prev以及next方法