MySQL – How to Use SHOW Connection_ID()

MySQL

In mysql, I can inspect the current Connection ID by using:

SELECT connection_id();

And it returns the id:

# connection_id()
'6558851'

Or:

SELECT * from information_schema.processlist 
WHERE id = connection_id();

# ID, USER, HOST, DB, COMMAND, TIME, STATE, INFO
'6558851', 'abc', '99-51-01-something:55353', 'XA', 'Query', '0', 'executing', 'select * from information_schema.processlist plist where id=connection_id()'

Where is that function (if it's a function?) defined though? I've checked in sys and information_schema and was unable to find a function defined with that name. Where is this located then?


Update, on reviewing this a bit more, it seems like these are just built-in functions to the mysql database — i.e., no different than using a GROUP_CONCAT() or any other function, for example:

SELECT connection_id(), now(), id, email FROM auth_user limit 10;

In this way it would be defined in the C++ code rather than as a user/system-defined function. Is that a correct understanding?

Best Answer

CONNECTION_ID() is a built-in function compiler in MySQL and therefore it is not contained in a database.

So yes, your understanding is correct.