Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Using Mysqldump to realize data restore of full database backup + binlog

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

With the growth of business, the database is also growing exponentially. The original full-database backup is no longer suitable for the current database. 10G-20G is easily backed up, which takes up too much disk space, so consider using a more concise, faster and more space-saving backup method. You have come up with the idea of using binlog logs for backup and recovery. Here are the specific implementation methods:

Environment introduction:

Operating system: Centos 7.2

Database: Mysql 5.6

one。 Install Mysql and change configuration files

Installation is not specific, there are many online tutorials, the configuration file needs to add the following options:

Vim / etc/my.cnf

Log_bin = mysql-binlog # enables the binlog log function, which is located under the datadir directory of mysql by default

Show variables like 'log_bin'; # enter Mysql to check whether the binlog log is enabled

two。 Create experimental data

Because of the newly built database, there is no data in the log, so create a new database and table to experiment.

# create T1 library

Create database t1

# create tab1 table

Create table t1.tab1 (id int primary key auto_increment,name varchar (20))

# insert two pieces of data

Insert into t1.tab1 (name) values ('zhangsan')

Insert into t1.tab1 (name) values ('lisi')

three。 Perform full library backup and log backup

# make a full database backup and generate new logs

Mysqldump-uroot-p123456-- flush-logs T1 > / opt/t1_ `date +% Y% m% d`.sql

# back up log files. Back up only a few logs before backing up the whole library.

Cp / usr/local/mysql/binlog/mysql.bin.000001 / opt/

four。 Simulated deletion of data

Delete from t1.tab1 where id=2

# insert new data

Insert into t1.tab1 (name) values ('wangwu')

five。 Back up the binlog log files after mysqldump

Cp / usr/local/mysql/binlog/mysql.bin.000002 / opt/

six。 Using Mysqldump to realize data restore of full database backup + binlog

Mysql-uroot-p123456 tab1 < / opt/t1_20170626.sql # restore all data before deletion, there should be two pieces of data, zhangsan and lisi

Mysqlbinlog-v / usr/local/mysql/binlog/mysql.bin.000002 # analyzes the newly opened binlog log file, and shows the starting and ending positions of the time of misoperation. Just skip this period of time.

Restore data from binlog

Mysqlbinlog-- stop-position=120 / opt/mysql.bin.000002 | mysql-uroot-p123456

Mysqlbinlog-- start-position=291 / opt/mysql.bin.000002 | mysql-uroot-p123456

View recovery status

Select * from t1.tab1; # at this time, there are three items of data in the table that have been successfully restored.

The manual backup and recovery process has been completed. Next time, talk about how to script this process.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report