当前位置:网站首页>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之哨兵模式
- Le modèle sentinelle de redis
- CSP salary calculation
- LeetCode:836. Rectangle overlap
- Master slave replication of redis
- [oc]- < getting started with UI> -- common controls uibutton
- Nacos 的安装与服务的注册
- LeetCode41——First Missing Positive——hashing in place & swap
- Different data-driven code executes the same test scenario
猜你喜欢
一改测试步骤代码就全写 为什么不试试用 Yaml实现数据驱动?
Blue Bridge Cup_ Single chip microcomputer_ Measure the frequency of 555
一篇文章带你了解-selenium工作原理详解
[OC foundation framework] - [set array]
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
[today in history] February 13: the father of transistors was born The 20th anniversary of net; Agile software development manifesto was born
A convolution substitution of attention mechanism
Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges
opencv+dlib实现给蒙娜丽莎“配”眼镜
LeetCode:498. Diagonal traversal
随机推荐
LeetCode:41. Missing first positive number
Advanced Computer Network Review(5)——COPE
xargs命令的基本用法
BN折叠及其量化
LeetCode:39. Combined sum
Selenium+pytest automated test framework practice (Part 2)
Redis cluster
Kratos战神微服务框架(二)
Mise en œuvre de la quantification post - formation du bminf
BMINF的後訓練量化實現
Digital people anchor 618 sign language with goods, convenient for 27.8 million people with hearing impairment
CSP student queue
[OC-Foundation框架]---【集合数组】
QML type: overlay
LeetCode:836. Rectangle overlap
Intel Distiller工具包-量化实现2
【shell脚本】——归档文件脚本
Improved deep embedded clustering with local structure preservation (Idec)
QML control type: menu
Persistence practice of redis (Linux version)