MySQL SYSTEM_USER() Function
The SYSTEM_USER()
function in MySQL provides a way to retrieve information about the currently active user's connection to the database server.
SYSTEM_USER(): Definition and Usage
SYSTEM_USER()
returns the user name and hostname of the current connection. This is very valuable for debugging, auditing, security, and logging. You can use it to identify who is accessing and interacting with your database.
Equivalent Functions
SYSTEM_USER()
is functionally identical to SESSION_USER()
and USER()
. They all return the same user and host information.
Syntax
Syntax
SYSTEM_USER()
Example
Retrieving User and Host Information
This query shows how to use SYSTEM_USER()
to get the username and hostname of the current connection.
Syntax
SELECT SYSTEM_USER();
Output
'your_username'@'your_hostname' (Example: 'john_doe'@'localhost')