在一个月前删除Mysql中删除的行有什么办法吗?

时间:2023-01-24 17:20:50

I am using Mysql and by mistake deleted very important details.Is there a way how to recover deleted records in Mysql?

我使用的是Mysql,错误地删除了非常重要的细节。有没有办法在Mysql中恢复被删除的记录?

2 个解决方案

#1


2  

I know this is not really what you are asking but I find it important that you know this.

我知道这不是你真正想问的,但我发现你知道这一点很重要。

The system I suggest is big data. It works as follow:

我建议的系统是大数据。它的工作原理是:

  1. Make a new column in your table (for ex the table people):

    在你的表格中新建一个列(例如表格中的人):

    ID  | Name   | Deleted
    1   | Bob    | 0
    2   | Frank  | 1
    3   | Alice  | 0
    

    With 0 as undeleted and 1 as deleted in last column with the type BOOLEAN. Name and ID are respectively a NVARCHAR and an INT

    在最后一列中,0为未删除,1为删除,类型为布尔。名称和ID分别是NVARCHAR和INT

  2. If you want delete a record, you don't delete it with a DELETE statement but update it like this:

    如果你想删除一个记录,你不需要删除它的删除语句,而是像这样更新:

    UPDATE people SET Deleted = 1 WHERE ID = 1
    

    Result:

    结果:

    ID  | Name   | Deleted
    1   | Bob    | 1
    2   | Frank  | 1
    3   | Alice  | 0
    

    You know ID's 1 and 2 are deleted because the boolean in column Deleted is on 1. Alice with ID 3 is not deleted because the boolean is on 0.

    你知道ID的1和2被删除因为删除列中的布尔值在1上。ID为3的Alice不会被删除,因为布尔值为0。


The pro of this system is that you can recover data with only one statement!

这个系统的优点是,您可以用一个语句恢复数据!

UPDATE people SET Deleted = 0 WHERE Deleted = 1

Result:

结果:

ID  | Name   | Deleted
1   | Bob    | 0
2   | Frank  | 0
3   | Alice  | 0

Now all record are recovered because the boolean in column Deleted is on 0.

现在所有记录都被恢复,因为删除的列中的布尔值为0。

If you use DELETE statement, it is impossible to recover all records! They are deleted for always and you can never recover it if you are using the DELETE statements. You can only use a backup file for recover it but has also contra's like:

如果使用DELETE语句,则不可能恢复所有记录!它们总是被删除,如果使用DELETE语句,则永远无法恢复。您只能使用一个备份文件来恢复它,但也有如下内容:

  • It's an old backup file,
  • 这是一个旧的备份文件,
  • I've forget to make one,
  • 我忘了做一个,
  • I don't know how you can make it,
  • 我不知道你怎么做,
  • I've lost it,
  • 我失去了它,
  • ...

By big data and his updates you change only one column and you have your data back.

通过大数据和他的更新,你只改变了一列,你就得到了你的数据。


Edit:
The contra of big data is that (like you have said) the data is not exactly remove from your database. It's only a column you change from 0 to 1. But if you know that you can make money from data... is this another story.

编辑:与大数据相反的是(如您所说)数据并没有从数据库中删除。它只是从0到1的一列。但如果你知道你可以从数据中赚钱…这是另一个故事。

If you want to delete it exactly you can use a DELETE statement. There are a lot of sites, programs, services that use big data, like:

如果你想删除它,你可以使用delete语句。有很多使用大数据的网站、程序和服务,比如:

  • Stack Overflow and the other communities of Stack Exchange (only comments are removed with a DELETE statement, questions not)
  • 栈溢出和栈交换的其他社区(只有注释用DELETE语句删除,没有问题)
  • Mail servers like GMail, Hotmail, Yahoo (from inbox to trash and then removed)
  • GMail、Hotmail、Yahoo等邮件服务器(从收件箱到垃圾邮件,然后删除)
  • Remove folders or files from your computer (from original location to trash and then removed)
  • 从计算机中删除文件夹或文件(从原始位置删除,然后删除)
  • Social media sites
  • 社交媒体网站
  • ...

For more information about big data you can look on this wikipedia article.

有关大数据的更多信息,请参阅*的这篇文章。

#2


1  

Do you have binlog files from the date where you insert these records ?

您是否有从插入这些记录的日期起的binlog文件?

Then you can get the inserts and put it back

然后你可以得到插入并把它放回去

#1


2  

I know this is not really what you are asking but I find it important that you know this.

我知道这不是你真正想问的,但我发现你知道这一点很重要。

The system I suggest is big data. It works as follow:

我建议的系统是大数据。它的工作原理是:

  1. Make a new column in your table (for ex the table people):

    在你的表格中新建一个列(例如表格中的人):

    ID  | Name   | Deleted
    1   | Bob    | 0
    2   | Frank  | 1
    3   | Alice  | 0
    

    With 0 as undeleted and 1 as deleted in last column with the type BOOLEAN. Name and ID are respectively a NVARCHAR and an INT

    在最后一列中,0为未删除,1为删除,类型为布尔。名称和ID分别是NVARCHAR和INT

  2. If you want delete a record, you don't delete it with a DELETE statement but update it like this:

    如果你想删除一个记录,你不需要删除它的删除语句,而是像这样更新:

    UPDATE people SET Deleted = 1 WHERE ID = 1
    

    Result:

    结果:

    ID  | Name   | Deleted
    1   | Bob    | 1
    2   | Frank  | 1
    3   | Alice  | 0
    

    You know ID's 1 and 2 are deleted because the boolean in column Deleted is on 1. Alice with ID 3 is not deleted because the boolean is on 0.

    你知道ID的1和2被删除因为删除列中的布尔值在1上。ID为3的Alice不会被删除,因为布尔值为0。


The pro of this system is that you can recover data with only one statement!

这个系统的优点是,您可以用一个语句恢复数据!

UPDATE people SET Deleted = 0 WHERE Deleted = 1

Result:

结果:

ID  | Name   | Deleted
1   | Bob    | 0
2   | Frank  | 0
3   | Alice  | 0

Now all record are recovered because the boolean in column Deleted is on 0.

现在所有记录都被恢复,因为删除的列中的布尔值为0。

If you use DELETE statement, it is impossible to recover all records! They are deleted for always and you can never recover it if you are using the DELETE statements. You can only use a backup file for recover it but has also contra's like:

如果使用DELETE语句,则不可能恢复所有记录!它们总是被删除,如果使用DELETE语句,则永远无法恢复。您只能使用一个备份文件来恢复它,但也有如下内容:

  • It's an old backup file,
  • 这是一个旧的备份文件,
  • I've forget to make one,
  • 我忘了做一个,
  • I don't know how you can make it,
  • 我不知道你怎么做,
  • I've lost it,
  • 我失去了它,
  • ...

By big data and his updates you change only one column and you have your data back.

通过大数据和他的更新,你只改变了一列,你就得到了你的数据。


Edit:
The contra of big data is that (like you have said) the data is not exactly remove from your database. It's only a column you change from 0 to 1. But if you know that you can make money from data... is this another story.

编辑:与大数据相反的是(如您所说)数据并没有从数据库中删除。它只是从0到1的一列。但如果你知道你可以从数据中赚钱…这是另一个故事。

If you want to delete it exactly you can use a DELETE statement. There are a lot of sites, programs, services that use big data, like:

如果你想删除它,你可以使用delete语句。有很多使用大数据的网站、程序和服务,比如:

  • Stack Overflow and the other communities of Stack Exchange (only comments are removed with a DELETE statement, questions not)
  • 栈溢出和栈交换的其他社区(只有注释用DELETE语句删除,没有问题)
  • Mail servers like GMail, Hotmail, Yahoo (from inbox to trash and then removed)
  • GMail、Hotmail、Yahoo等邮件服务器(从收件箱到垃圾邮件,然后删除)
  • Remove folders or files from your computer (from original location to trash and then removed)
  • 从计算机中删除文件夹或文件(从原始位置删除,然后删除)
  • Social media sites
  • 社交媒体网站
  • ...

For more information about big data you can look on this wikipedia article.

有关大数据的更多信息,请参阅*的这篇文章。

#2


1  

Do you have binlog files from the date where you insert these records ?

您是否有从插入这些记录的日期起的binlog文件?

Then you can get the inserts and put it back

然后你可以得到插入并把它放回去