# Function to get binlog details for the given GTID in MySQL

**URL:** <https://forums.percona.com/t/function-to-get-binlog-details-for-the-given-gtid-in-mysql/35968>\
**Category:** MySQL & MariaDB\
**Tags:** mysql\
**Created:** [January 4, 2025, 3:56pm UTC](https://forums.percona.com/t/function-to-get-binlog-details-for-the-given-gtid-in-mysql/35968 "2025-01-04T15:56:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![preethi\_subbu](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/preethi_subbu/32/3204_2.png) [@preethi\_subbu](https://forums.percona.com/u/preethi_subbu)\
**Post date:** [January 4, 2025, 3:56pm UTC](https://forums.percona.com/t/function-to-get-binlog-details-for-the-given-gtid-in-mysql/35968/1 "2025-01-04T15:56:55Z")

</div>

Hello,

I am working with MySQL 8 and need to retrieve the binlog file name and position from a given GTID (Global Transaction Identifier). Could anyone please help me with the function or query to get this information?

Any assistance would be highly appreciated. Thanks in advance!

* * *

---

<div class="post-metadata">

**Author:** ![matthewb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/matthewb/32/34_2.png) [@matthewb](https://forums.percona.com/u/matthewb)\
**Post date:** [January 4, 2025, 9:12pm UTC](https://forums.percona.com/t/function-to-get-binlog-details-for-the-given-gtid-in-mysql/35968/2 "2025-01-04T21:12:45Z")

</div>

Hello @preethi_subbu,  
I could not find any functions for doing this. Your best solution is using mysqlbinlog on a few log files and simply grep’ing for the GTID. You can use glob-style filename pattern to the mysqlbinlog tool to make it easier.

---

<div class="post-metadata">

**Author:** ![anil.joshi](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/anil.joshi/32/13100_2.png) [@anil.joshi](https://forums.percona.com/u/anil.joshi)\
**Post date:** [January 17, 2025, 12:51pm UTC](https://forums.percona.com/t/function-to-get-binlog-details-for-the-given-gtid-in-mysql/35968/3 "2025-01-17T12:51:40Z")

</div>

@preethi_subbu Also, If you using Percona (PS) MySQL 8 then you have the feasibility to use some user defined function.

For e.g,

```auto
mysql> CREATE FUNCTION get_binlog_by_gtid_set RETURNS STRING SONAME 'binlog_utils_udf.so';
Query OK, 0 rows affected (0.02 sec)

```

```auto
mysql> SELECT CAST(get_binlog_by_gtid_set("cbe2b67f-d4a1-11ef-af5a-52103420acdc:1-13") AS CHAR) AS result;
+---------------+
| result |
+---------------+
| binlog.000002 |
+---------------+
1 row in set (0.00 sec)

```

You can check the same along with some other binary log/gtid set related functions here - [Binary logs and replication improvements - Percona Server for MySQL](https://docs.percona.com/percona-server/8.0/binlogging-replication-improvements.html#binary-log-user-defined-functions)
