In MariaDB, every thread (including each event) has an ID that is unique among the set of currently connected clients. The CONNECTION_ID()
function is a built-in function that returns the connection ID (thread ID) for the connection.
Syntax
The syntax goes like this:
CONNECTION_ID()
So, no arguments are required or accepted.
Example
Here’s an example to demonstrate:
SELECT CONNECTION_ID();
Result:
+-----------------+ | CONNECTION_ID() | +-----------------+ | 6 | +-----------------+
In my case, the connection ID is 6
.
If I connect to MariaDB from a new terminal window:
mariadb
And run the statement again:
SELECT CONNECTION_ID();
Here’s what I get:
+-----------------+ | CONNECTION_ID() | +-----------------+ | 7 | +-----------------+
No Arguments are Accepted
Passing any arguments to CONNECTION_ID()
results in an error:
SELECT CONNECTION_ID(1);
Result:
ERROR 1582 (42000): Incorrect parameter count in the call to native function 'CONNECTION_ID'