MySQL SESSION_USER() Function

The SESSION_USER() function in MySQL provides a simple way to retrieve information about the currently active user's connection to the database.



SESSION_USER(): Definition and Usage

This function returns the current user's name and the hostname from which they're connected. It's a very useful function for debugging, auditing, and security-related tasks within your MySQL applications.

Equivalents

It's important to note that SESSION_USER() is functionally identical to both SYSTEM_USER() and USER(). You can use any of these three functions interchangeably to get the same result.

Syntax

Syntax

SESSION_USER()
      

Example

Retrieving the User and Host

The following query demonstrates how to use SESSION_USER() to obtain the current user's name and host.

Syntax

SELECT SESSION_USER();
      
Output

'user_name'@'hostname'  (Example output - the actual output will depend on your MySQL connection)