HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Does MySQL support querying for the current running transaction id

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
thequeryingmysqlrunningfordoescurrenttransactionsupport

Problem

PostgreSQL supports retrieving the current running transaction id using a query like this:

select txid_current();


Does MySQL have any such equivalent?

Solution

Starting with MySQL 5.7, you can see the current transactions in the performance schema.

See http://dev.mysql.com/doc/refman/5.7/en/events-transactions-current-table.html

Now, to find out the THREAD_ID of the current connection, use

SELECT THREAD_ID FROM performance_schema.threads
  WHERE PROCESSLIST_ID = CONNECTION_ID()


See http://dev.mysql.com/doc/refman/5.7/en/threads-table.html

Code Snippets

SELECT THREAD_ID FROM performance_schema.threads
  WHERE PROCESSLIST_ID = CONNECTION_ID()

Context

StackExchange Database Administrators Q#98954, answer score: 5

Revisions (0)

No revisions yet.