Neither MariaDB nor MySQL can send data to clients without a previous request from the client.
Tracking the GTID is supported by several client connectors (like MariaDB Connector/C or MariaDB Connector/Python) where the GTID will be obtainted from the session state information of the OK packet from previous commit.
Here is a simple example in Python:
import mariadb
def status_tracker(connection, status):
if 'last_gtid' in status:
print("last_gtid changed: %s" % status['last_gtid'])
conn= mariadb.connect(status_callback=status_tracker, db="test")
cursor= conn.cursor()
# tell the server to submit last_gtid in session_state_information
cursor.execute("SET @@session.session_track_system_variables='last_gtid'")
cursor.execute("CREATE TEMPORARY TABLE t1 (a int)")
conn.commit()
cursor.execute("CREATE TEMPORARY TABLE t2 (a int)")
conn.commit()
cursor.execute("SET gtid_seq_no=1000")
cursor.execute("CREATE TEMPORARY TABLE t3 (a int)")
conn.commit()
Result/Output:
last_gtid changed: 0-1-40802
last_gtid changed: 0-1-40803
last_gtid changed: 0-1-1000