温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

mysql误删除表内数据怎么办

发布时间:2021-11-02 09:49:43 来源:亿速云 阅读:149 作者:小新 栏目:MySQL数据库

这篇文章主要介绍了mysql误删除表内数据怎么办,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

#添加数据

insert into testdb1.student(id,name,class,score) value(a,'a',1,45),(2,'b',1,46),(3,'c',2,89),(4,'d',2,90),(5,'e',3,67),(6,'f',3,87),(7,'g',4,77),(8,'h',4,91);

mysql> select * from testdb1.student;

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

| id   | name | class | score |

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

|    1 | a    | 1     |    45 |

|    2 | b    | 1     |    46 |

|    3 | c    | 2     |    89 |

|    4 | d    | 2     |    90 |

|    5 | e    | 3     |    67 |

|    6 | f    | 3     |    87 |

|    7 | g    | 4     |    77 |

|    8 | h    | 4     |    91 |

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

8 rows in set (0.00 sec)

#删除数据

mysql> delete from testdb1.student;

Query OK, 8 rows affected (0.00 sec)

mysql> commit;

Query OK, 0 rows affected (0.00 sec)

mysql> show master status\G

*************************** 1. row ***************************

             File: ray-bin.000004

         Position: 5444

     Binlog_Do_DB:

Binlog_Ignore_DB:

Executed_Gtid_Set:

1 row in set (0.00 sec)

[root@localhost ~]# mysqlbinlog /data/3306/logs/ray-bin.000004 -v -v -S /data/3306/soket/mysql.sock --base64-output=decode-rows | sed -n '/### DELETE FROM `testdb1`.`student`/,/COMMIT/P' | sed -n 's\### \\p' | sed "s/\/\*.*\*\///g" | sed 's/`//g' > /tmp/1.txt

[root@localhost ~]# sed 's/DELETE FROM/insert into/g' /tmp/1.txt | sed 's/WHERE/select/g' | sed 's/@4.*/\0;/g' | sed 's/@[1-3].*/\0,/g' | sed 's/[^@]\(.*\)=//g' > execSQL.sql

要点:

     sed 's/@4.*/\0;/g'  把@4后面匹配所有字符所有长度,替换,在匹配的后面添加。\0代表整行;

     sed 's/@[1-3].*/\0,/g'    把@后面从1到3匹配,在匹配后面所有字符所有长度,在匹配项后面添加逗号。\0代表整行。

     sed 's/[^@]\(.*\)=//g'  把已@开头的到=以内的内容替换

mysql> source /root/execSQL.sql

Query OK, 1 row affected (0.00 sec)

Records: 1  Duplicates: 0  Warnings: 0

Query OK, 1 row affected (0.00 sec)

Records: 1  Duplicates: 0  Warnings: 0

Query OK, 1 row affected (0.00 sec)

Records: 1  Duplicates: 0  Warnings: 0

Query OK, 1 row affected (0.00 sec)

Records: 1  Duplicates: 0  Warnings: 0

Query OK, 1 row affected (0.00 sec)

Records: 1  Duplicates: 0  Warnings: 0

Query OK, 1 row affected (0.00 sec)

Records: 1  Duplicates: 0  Warnings: 0

Query OK, 1 row affected (0.00 sec)

Records: 1  Duplicates: 0  Warnings: 0

Query OK, 1 row affected (0.00 sec)

Records: 1  Duplicates: 0  Warnings: 0

mysql> commit;

Query OK, 0 rows affected (0.01 sec)

mysql> select * from testdb1.student;

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

| id   | name | class | score |

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

|    1 | a    | 1     |    45 |

|    2 | b    | 1     |    46 |

|    3 | c    | 2     |    89 |

|    4 | d    | 2     |    90 |

|    5 | e    | 3     |    67 |

|    6 | f    | 3     |    87 |

|    7 | g    | 4     |    77 |

|    8 | h    | 4     |    91 |

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

8 rows in set (0.00 sec)

感谢你能够认真阅读完这篇文章,希望小编分享的“mysql误删除表内数据怎么办”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI