需求:查出有哪些 IP 修改了表 sod_song_artist_relation。
方案:init_connect + mysqlbinlog
步骤:
use test;
create table accesslog(`thread_id` int primary key, `time` timestamp, `localname` varchar(40), `machine_name` varchar(40));
mysql> show variables like 'init%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| init_connect | |
| init_file | |
| init_slave | |
+---------------+-------+
3 rows in set (0.00 sec)
mysql> set global init_connect='insert into test.accesslog(thread_id,time,localname,machine_name) values(connection_id(),now(),user(),current_user());';
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like 'init%';
+---------------+-----------------------------------------------------------------------------------------------------------------------+
| Variable_name | Value |
+---------------+-----------------------------------------------------------------------------------------------------------------------+
| init_connect | insert into dba.accesslog(thread_id,time,localname,machine_name) values(connection_id(),now(),user(),current_user()); |
| init_file | |
| init_slave | |
+---------------+-----------------------------------------------------------------------------------------------------------------------+
3 rows in set (0.00 sec)
mysql> grant all on test.accesslog to songod;
Query OK, 0 rows affected (0.00 sec)
cd /data/dblog/
mysqlbinlog mysql-bin.002349 --base64-output=decode-rows -v > a.log
grep -n -B15 "UPDATE \`songod\`.\`sod_song_artist_relation\`" a.log | grep thread_id | awk '{print $11}' | awk -F= '{print $2","}' | sort -n | uniq
# 返回
276867518,
276867551,
277068047,
mysql> select * from test.accesslog where thread_id in (276867518, 276867551, 277068047) order by thread_id;
+-----------+---------------------+---------------------+--------------+
| thread_id | time | localname | machine_name |
+-----------+---------------------+---------------------+--------------+
| 276867518 | 2024-04-29 18:12:19 | songod@172.18.8.134 | songod@% |
| 276867551 | 2024-04-29 18:12:28 | songod@172.18.8.133 | songod@% |
| 277068047 | 2024-04-30 10:43:12 | songod@172.18.8.134 | songod@% |
+-----------+---------------------+---------------------+--------------+
3 rows in set (0.00 sec)
set global init_connect='';
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有