MariaDB CONNECTION_ID() Function

In MariaDB, CONNECTION_ID() is a built-in function that returns the unique ID for the current connection. For each connection, MariaDB will assign a unique ID.

MariaDB CONNECTION_ID() Syntax

Here is the syntax of the MariaDB CONNECTION_ID() function:

CONNECTION_ID()

Parameters

The MariaDB CONNECTION_ID() function do not require any parameters.

If you supply an argument, MariaDB will report an error: ERROR 1582 (42000): Incorrect parameter count in the call to native function 'CONNECTION_ID'.

Return value

The MariaDB CONNECTION_ID() function returns the unique connection ID for the current connection.

MariaDB CONNECTION_ID() Examples

The following example shows how to use the CONNECTION_ID() function to get the unique connection ID of the current connection.

SELECT CONNECTION_ID();

Output:

+-----------------+
| CONNECTION_ID() |
+-----------------+
|               3 |
+-----------------+

If I connect to MariaDB from a new terminal window, and run the statement again:

SELECT CONNECTION_ID();

Here’s what I get:

+-----------------+
| CONNECTION_ID() |
+-----------------+
|               4 |
+-----------------+

Conclusion

In MariaDB, CONNECTION_ID() is a built-in function that returns the unique connection ID for the current connection.