# Getting host which executed the query in results

**URL:** <https://forums.percona.com/t/getting-host-which-executed-the-query-in-results/18167>\
**Category:** Uncategorized\
**Tags:** percona\
**Created:** [October 24, 2022, 10:11pm UTC](https://forums.percona.com/t/getting-host-which-executed-the-query-in-results/18167 "2022-10-24T22:11:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joseph85750](https://avatars.discourse-cdn.com/v4/letter/j/e47774/32.png) [@joseph85750](https://forums.percona.com/u/joseph85750)\
**Post date:** [October 24, 2022, 10:11pm UTC](https://forums.percona.com/t/getting-host-which-executed-the-query-in-results/18167/1 "2022-10-24T22:11:36Z")

</div>

I have a mysql database and I’m trying to analyze the log files with pt-query-digest.  
I can do a simple:  
`pt-query-digest --type genlog --report-all --limit=100% mysql.log > results.txt`

Which captures a lot of data, but I’d like to have the results also include the **IP of the client** which executed the query.

I found I can do this:  
`pt-query-digest --type genlog --report-all --limit=100% --group-by host mysql.log > results2.txt`

Which returns a much smaller list including the IP of the client, but then I don’t get the query itself which was executed. My goal is to get a list of all the queries executed and include the client IP from which the query was executed.  
Can this be done?

---

<div class="post-metadata">

**Author:** ![Mauricio\_Cacho](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/mauricio_cacho/32/5859_2.png) [@Mauricio\_Cacho](https://forums.percona.com/u/Mauricio_Cacho)\
**Post date:** [October 25, 2022, 12:17am UTC](https://forums.percona.com/t/getting-host-which-executed-the-query-in-results/18167/2 "2022-10-25T00:17:13Z")

</div>

Hi @joseph85750. Is there a particular reason on why you’re using general log for this?

If the result you’re looking for is have all the queries executed and the IP, you could enable the [slow query log](https://dev.mysql.com/doc/refman/8.0/en/slow-query-log.html), at least with the following parameters:

- slow\_query\_log=1
- long\_query\_time=0 (So every query get recorded).
- slow\_query\_log\_file=/your/desired/path.log

You could modify the following as well, based on your requirements:

- log\_slow\_admin\_statements
- log\_slow\_extra
- log\_slow\_replica\_statements

And then you could use pt-query-digest with the slow query log as the source.

Best,  
Mauricio.

---

<div class="post-metadata">

**Author:** ![joseph85750](https://avatars.discourse-cdn.com/v4/letter/j/e47774/32.png) [@joseph85750](https://forums.percona.com/u/joseph85750)\
**Post date:** [October 25, 2022, 12:21pm UTC](https://forums.percona.com/t/getting-host-which-executed-the-query-in-results/18167/3 "2022-10-25T12:21:41Z")

</div>

I’m using the general log because I want all queries, and not just the slow queries. It was my understanding that the slow query log doesn’t log all queries. Maybe I misunderstood?

---

<div class="post-metadata">

**Author:** ![Michael\_Coburn](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/michael_coburn/32/18_2.png) [@Michael\_Coburn](https://forums.percona.com/u/Michael_Coburn)\
**Post date:** [October 25, 2022, 1:52pm UTC](https://forums.percona.com/t/getting-host-which-executed-the-query-in-results/18167/4 "2022-10-25T13:52:24Z")

</div>

The slow query log will log every query running longer than the threshold [long\_query\_time](https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_long_query_time). This means you can set `long_query_time=0` and capture all queries.  
Note the difference is that General Log writes the query when it begins (so successful and failed queries are logged), whereas slow log writes after the query has completed. This has the advantage of including valuable information such as pages read from disk, lock wait times, and query run time.
