Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What if mysql deletes the data in the table by mistake?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the mysql mistakenly deleted table data how to do, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor with you to understand.

# add data

Insert into testdb1.student (id,name,class,score) value (arecronomy) value (arecronomy), (2) (2) (2) (3) (3) (3) (3) (3) (3) (4) (4) (4) (4) (4) (4) (4), (4) (4), (4) (4), (4) (4), (4) (4) (4), (4) (4) (4), (4) (4) (4) (4) (4) (4) (4) (4) (4) (4) (4) (4) (4) (4) (4) (4) (4) (4) (4) (4) (4) (4) (4) (4) (4) (4) (4) (4) (4) (4) (

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)

# Delete data

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-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 sed where select execSQL.sql g' | sed's execSQL.sql = / / g' > execSQL.sql = / / g'>

Main points:

Sed's swap 4. 4. /\ 0 match the full length of all characters after @ 4, replace, and add after the match. \ 0 represents the whole line

Sed's swap @ [1-3]. * /\ 0Grample G' matches @ from 1 to 3, all characters after the match are all lengths, and a comma is added after the match. \ 0 represents the whole line.

Sed's / [^ @]\ (. *\) = / / g' replace the content that starts with @ and falls within =.

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)

Thank you for reading this article carefully. I hope the article "how to delete the data in the table by mysql" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report