Restore process after phpmyadmin accidentally deletes the table (stunned) _ MySQL

Source: Internet
Author: User
Restore process after phpmyadmin accidentally deletes the table (stunned) Restore process after phpmyadmin accidentally deletes the table (stunned) _ MySQL

Today, I don't know whether it is a good news or a bad news. when I used phpmyadmin to delete the test data, I actually deleted the entire table:

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:

And 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: * puts forward the operation records of the corresponding table in the file exported by the binary log * @ 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 ();/** if it is an update operation, directly propose */if (t2.startsWith ("UPDATE" + table) {bw. append (t + "; \ n") ;}/ ** if it is an insert statement, because there are some old server data *, 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") ;}/ ** the SQL statement must be followed by the; because it didn't exist before. if it is not added, when importing data to the database, error */} 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 ..) Finally, we would like to remind you that you must always back up data and proceed with caution!

The above is the recovery process after phpmyadmin accidentally deletes the table (stunned) _ MySQL content. For more information, see The PHP Chinese website (www.php1.cn )!

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.