需求:数据库某表的数据没有了;如何找是什么时修改清掉的;
思路:
1. 查代码,找某表的删除接口,分析是在哪里调用;【部分服务log不全】
2. 查服务的log;【部分服务log不全】
3. 查数据库的操作日志biglog; 【有开biglog】
查所有日志;【没解码只能查部分关键字】,没什么用
mysql -uroot -p123456 show binlog events in 'mysql-bin.000007';
查找create【没解码只能查部分关键字】,没什么用
mysql -uroot -p123456 -e "show binlog events in 'mysql-bin.000007'" |grep "create" mysql -uroot -p123456 -e "show binlog events in 'mysql-bin.000007'" |grep "base_product_point_desc"
(没时间)
查找create,输出前5后5行【没解码只能查部分关键字】
mysqlbinlog /usr/local/mysql/data/mysql-bin.000007 | grep -A 5 -B 5 'CREATE TABLE' mysqlbinlog /usr/local/mysql/data/mysql-bin.00000* | grep 'create'
查找base_product_point_desc表
mysqlbinlog /usr/local/mysql/data/mysql-bin.000007 | grep 'base_product_point_desc'
(没时间)
查找base_product_point_desc表,输出前5后5行【没解码只能查部署关键字】
mysqlbinlog /usr/local/mysql/data/mysql-bin.000007 | grep -A 5 -B 5 'base_product_point_desc'
(有时间)
管用的:
1.导入指定日期的解码后的sql:【解码查所有关键字】
mysqlbinlog --no-defaults --database=onehome_100950784 --start-datetime="2024-04-01 00:00:00" --stop-datetime="2024-04-11 12:00:00" --base64-output=decode-rows -vvv /usr/local/mysql/data/mysql-bin.00* > tt.txt
可查所有关键字: create、DELETE、truncate、pghxugfy2ha32tdv、DELETE FROM onehome_100950784
.base_product_point_desc
等;
2. 查找DELETE FROM onehome_100950784
.base_product_point_desc
,并输出前5后10行内容到文本:【注释转义】
less tt.txt|grep -A 20 -B 5 "DELETE FROM `onehome_100950784`.`base_product_point_desc`" >t2.txt
3.再查id:pghxugfy2ha32tdv less t2.txt回车,再输入pghxugfy2ha32tdv回车查找;