0

I establish the master-slave replication based on GTID. And i want to get the newest GTID of master or slave, I know the way of getting GTID by show variables like '%gtid%', but this way requires constant timed query. Is there any way about mariadb server can active notice if I provide a script or a function.

if I provide a script or a function,Mmariadb server can active notice the newest GTID

1 Answers1

2

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
Georg Richter
  • 5,970
  • 2
  • 9
  • 15