Mysql data table and record deleted by mistake and restored by binary

Source: Internet
Author: User
Tags phpmyadmin

 

When an error occurs during the running of the program, the entire table is no longer displayed, and the backup has not been completed before! It hurts. This is a production server. Can the data in it be lost!

 

I am not familiar with the linux server and do not know where mysql is installed.

 

In desperation, google found that many people were as stupid as I did, but almost did not see the specific solution (some say that hard disk software was used for retrieval, but I don't know much about the server, and I think it's hard to find a binary file. I'm urging you to find the data.

 

Now I am in a hurry and have no mood to eat dinner.

 

At this time, I found some technical staff dedicated to helping people restore data.

 

He asked me about the data volume and database engine. When I said "myisam", he came up with the following sentence: no solution ..

 

At that time, I suddenly crashed.

 

In a hurry, I thought that there was a replica database in the testing server, but the data there had not been the latest data for a month.

 

This cannot save me!

 

Here I see this in phpmyadmin:

 

 

 

If the binary data is recovered on google, click here. The results are amazing! OMG. Logs are activated on the server!

 

 

 

There are Database operation logs in the SQL format !!!

 

I have never touched this thing before, but it is my lifeline.

 

I browsed it and there was an update record for nearly a month, which is enough. However, there is a problem. In phpmyadmin, only a small part of the content can be displayed. It is too difficult to find the data of the table to be deleted one by one in the face of data rows of hundreds of thousands.

 

At this time, I thought of downloading these files from the server and getting the data.

 

Just do it. I log on to the server and search for these binary files:

 

 

 

The red circle is shown in the figure above.

 

Then export these files one by one into readable SQL:

 

 

 

In this way, these binary files are output into normal SQL files one by one.

 

At this time, we need to find the data related to the table to be deleted from these files, so I wrote a java program to help me do this:

 

Package com. nerve. SQL. reload;

 

Import java. io. BufferedReader;

 

Import java. io. BufferedWriter;

 

Import java. io. FileReader;

 

Import java. io. FileWriter;

 

Import java. util. ArrayList;

 

Import java. util. List;

 

Import org. nerve. util. NumberUtil;

 

/**

 

* @ Project: cloudOffice_swing

 

* @ File: ReloadWorker. java

 

* @ Package: com. nerve. SQL. reload

 

* @ Description:

 

* Extract the operation records of the corresponding tables in the files exported from binary logs.

 

* @ Author: integrated graphics card 1053214511@qq.com

 

* @ Date & time: Jan 23,201 4

 

* @ Change log:

 

*/

 

Public class ReloadWorker {

 

Public void read (List orgF, String targetF, String table) throws Exception {

 

BufferedWriter bw = new BufferedWriter (new FileWriter (targetF, true ));

 

For (String or: orgF ){

 

BufferedReader br = new BufferedReader (new FileReader (or ));

 

String t = null;

 

String t2 = null;

 

Table = table. toUpperCase ();

 

While (t = br. readLine ())! = Null ){

 

T2 = t. toUpperCase ();

 

/*

 

* For update operations, directly submit

 

*/

 

If (t2.startsWith ("UPDATE" + table )){

 

Bw. append (t + "; \ n ");

 

}

 

/*

 

* If it is an insert statement, because there are some old server data

 

* Therefore, you must first perform the delete operation.

 

*/

 

Else if (t2.startsWith ("insert into" + table )){

 

String ids = t2.substring (t2.lastIndexOf (","));

 

Bw. append ("delete from" + table + "where id =" + NumberUtil. toDigital (ids) + "; \ n ");

 

Bw. append (t + "; \ n ");

 

}

 

/*

 

* An error occurs when an SQL statement is imported to the database because it is not added.

 

*/

 

}

 

Br. close ();

 

}

 

Bw. flush ();

 

Bw. close ();

 

}

 

Public static void main (String [] args) throws Exception {

 

Long sd = System. currentTimeMillis ();

 

ReloadWorker w = new ReloadWorker ();

 

List orgs = new ArrayList ();

 

Orgs. add ("C:/Users/IBM_ADMIN/Desktop/000015.txt ");

 

Orgs. add ("C:/Users/IBM_ADMIN/Desktop/logs 16.txt ");

 

Orgs. add ("C:/Users/IBM_ADMIN/Desktop/000017.txt ");

 

Orgs. add ("C:/Users/IBM_ADMIN/Desktop/000018.txt ");

 

Orgs. add ("C:/Users/IBM_ADMIN/Desktop/000019.txt ");

 

String targetS = "C:/Users/IBM_ADMIN/Desktop/000017_ SQL .txt ";

 

W. read (orgs, targetS, "task ");

 

System. out. println ("DONE, on" + (System. currentTimeMillis ()-sd)/1000 + "s ");

 

}

 

}

 

After the summary SQL file is obtained, it is imported to the database.

 

Finally, a runtime diagram is displayed:

 

 

 

I finally breathed a sigh of relief. (Although this import took 5 minutes ..)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.