A customer recently asked for a way to compare the transaction sets between servers. That is useful when setting up replication or identifying the server that has most transactions applied already. So I wrote this little script which can be executed from the OS shell:
#!/usr/bin/mysqlsh -f
// it is important to connect to the X protocol port,
// usually it is the traditional port + "0"
//
var serverA="root:root@localhost:40010"
var serverB="root:root@localhost:50010"
shell.connect(serverA)
var gtidA=session.sql("SELECT @@global.gtid_executed").execute().fetchOne()[0]
shell.connect(serverB)
var gtidB=session.sql("SELECT @@global.gtid_executed").execute().fetchOne()[0]
//
// If you want to use pure XdevAPI the former statements should be
//
// gtid = session.getSchema("performance_schema").global_variables.select("VARIABLE_VALUE").where("VARIABLE_NAME='gtid_executed'").execute().fetchOne()[0]
//
println(" ")
println ("Transactions that exist only on "+serverA)
println (session.sql("SELECT gtid_subtract('"+gtidA+"','"+gtidB+"')").execute().fetchOne()[0])
println(" ")
println ("Transactions that exist only on "+serverB)
println (session.sql("SELECT gtid_subtract('"+gtidB+"','"+gtidA+"')").execute().fetchOne()[0])