search
HomeDatabaseMysql Tutorial通过Mysql-bin日志恢复还原数据

提取出来后,里面就是所有对terminfo的sql语句了,把这些数据导入到测试库terminfo0730表中

事情是这样的:由于个人粗心,在7月30号那天协助其它部门批量更新一些数据,谁知道全局更新了,而这个问题竟然在9月26号才发现告知我。他们要求把更新有误的数据恢复到7月30号之前状态,并且7月30号到9月26号这段时间所做的增删改的操作也要更新进去。由于之前没啥经验,心里也没底,但是没办法,自己做错事自己承担。

做法思路:把备份的数据导到测试库里面去,然后把7月30号到9月26号之间的binlog日志提取出对这个表进行操作的sql语句,然后再导进去。

苦逼的还原过程开始了.........

1.幸好本人养成了个好习惯,无论改动的大小我都会先备份一份数据

-rw-r--r-- 1 root root 2473664 07-30 09:38 terminfo-bak0730.sql

找到了,果然是7月30号早上09点38分左右备份的,幸好有备份啊,要不然就悲催了.......先把备份的导到测试数据库上,表名改为terminfo0730,然后再把当前生产的数据导到,表名改为terminfo0926,这样的做法是在还原数据后匹配一下数据有没有对得上。






+----------------+

2.最重要的一步来了,,就是提取binlog日志。因为7月30号备份的,所以要找7月30号之后到9月26号的binlog。





利用mysqlbinlog命令先进行第一轮的sql语句提取

#mysqlbinlog --no-defaults --database=ecard --start-datetime='2012-07-30 09:38:00' mysql-bin.000086 > log86.txt  # 这里要设置起始时间
#mysqlbinlog --no-defaults --database=ecard  mysql-bin.000087 > log87.txt
#mysqlbinlog --no-defaults --database=ecard  mysql-bin.000088 > log88.txt
#mysqlbinlog --no-defaults --database=ecard  mysql-bin.000089 > log89.txt
#mysqlbinlog --no-defaults --database=ecard  mysql-bin.000090 > log90.txt

#ls -l




提取出来后是全部的sql语句,而我需要的是只对terminfo操作的sql语句,所以要进行第二轮提取

#grep terminfo log86.txt > log86-terminfo.txt #依次grep出来





提取出来后,里面就是所有对terminfo的sql语句了,把这些数据导入到测试库terminfo0730表中

mysql > source log86-terminfo.txt; #依次source进去,务必要注意顺序问题!!!

导进去之后再比较一下terminfo0730和terminfo0926表的数据数量有没有一样,然后再叫部门同事验证一下数据正确性。

到此,数据成功恢复还原。一次难忘的经历啊,也同时告诫自己,细心细心再细心!!

linux

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What Are the Limitations of Using Views in MySQL?What Are the Limitations of Using Views in MySQL?May 14, 2025 am 12:10 AM

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

Securing Your MySQL Database: Adding Users and Granting PrivilegesSecuring Your MySQL Database: Adding Users and Granting PrivilegesMay 14, 2025 am 12:09 AM

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

What Factors Influence the Number of Triggers I Can Use in MySQL?What Factors Influence the Number of Triggers I Can Use in MySQL?May 14, 2025 am 12:08 AM

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

MySQL: Is it safe to store BLOB?MySQL: Is it safe to store BLOB?May 14, 2025 am 12:07 AM

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

MySQL: Adding a user through a PHP web interfaceMySQL: Adding a user through a PHP web interfaceMay 14, 2025 am 12:04 AM

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools