A
A
Alexander2017-06-07 11:26:45
linux
Alexander, 2017-06-07 11:26:45

How to catch a specific query in MySql?

Hello colleagues!
Please advise how to solve the following problem.
There are many servers and a large database with tables. There is an insert into a certain table and it is impossible to catch from which ip the request is being made. The looped bash script used with the query did not return any results:

#!/bin/bash

c=1
while [ "$c" ]
do
sleep 6
mysql -e "show processlist;" | grep 'insert into nametable' >> nametable.log
done

Recommended to run and configure MySql-Proxy. What other options are there?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mishania666, 2017-06-07
@mishania666

Make a trigger on the table on, for example, BEFORE INSERT, write data to another table, the address of the host that launched the query can be found like this:

SELECT substring_index(host,':',1) ip 
FROM information_schema.processlist 
WHERE id = connection_id();

C
champloootaku, 2017-06-07
@champloootaku

2 options.
1. mytop (similar to show full processlist;)
If the request is processed very quickly, you can include before the request:

mysql -p
SET global general_log = 1;
###выполняем запрос###
SET global general_log = 0;

Then we look where you have general log.
For example /var/lib/mysql/server.log
or maybe /var/log/mysql.log
Good luck! :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question