当前位置:网站首页>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"
边栏推荐
- postman之参数化详解
- Redis之核心配置
- [Hacker News Weekly] data visualization artifact; Top 10 Web hacker technologies; Postman supports grpc
- [shell script] - archive file script
- Compétences en mémoire des graphiques UML
- Export IEEE document format using latex
- Notes 01
- [OC-Foundation框架]--<Copy对象复制>
- [OC-Foundation框架]---【集合数组】
- Redis之五大基础数据结构深入、应用场景
猜你喜欢
Redis之哨兵模式
Once you change the test steps, write all the code. Why not try yaml to realize data-driven?
[today in history] February 13: the father of transistors was born The 20th anniversary of net; Agile software development manifesto was born
Redis之连接redis服务命令
Redis之五大基础数据结构深入、应用场景
Booking of tourism products in Gansu quadrupled: "green horse" became popular, and one room of B & B around Gansu museum was hard to find
【图的三大存储方式】只会用邻接矩阵就out了
SimCLR:NLP中的对比学习
LeetCode:498. Diagonal traversal
Blue Bridge Cup_ Single chip microcomputer_ PWM output
随机推荐
【图的三大存储方式】只会用邻接矩阵就out了
CUDA implementation of self defined convolution attention operator
LeetCode:124. Maximum path sum in binary tree
多元聚类分析
[OC-Foundation框架]---【集合数组】
I-BERT
UML圖記憶技巧
LeetCode:394. String decoding
IJCAI2022论文合集(持续更新中)
After reading the programmer's story, I can't help covering my chest...
Intel Distiller工具包-量化实现3
[OC]-<UI入门>--常用控件-提示对话框 And 等待提示器(圈)
Compétences en mémoire des graphiques UML
LeetCode:34. Find the first and last positions of elements in a sorted array
[OC]-<UI入门>--常用控件的学习
Redis之哨兵模式
Blue Bridge Cup_ Single chip microcomputer_ Measure the frequency of 555
Advance Computer Network Review(1)——FatTree
[daily question] Porter (DFS / DP)
CSP student queue