The SYSTEM_USER() function returns the current user name and host name for the MySQL connection.
Syntax
SYSTEM_USER()
Definition and Usage
- The
SYSTEM_USER()function provides information about the user name and host name associated with the current MySQL connection. - This function is used to identify which user is connected to the MySQL server.
- It returns a string formatted as
user_name@host_name.
Technical Details
- Works in: From MySQL 4.0
- Note: This function is functionally equivalent to
SESSION_USER()andUSER(), as all three functions return the current user information. However,SYSTEM_USER()is typically used to indicate the system user of the current connection.
Examples
Example 1: Retrieve the current system user and host name
SELECT SYSTEM_USER();
Result:
'username@hostname'
This will return the user name and host name associated with the current MySQL session.
Example 2: Use with other session details
SELECT SYSTEM_USER(), NOW();
Result:
'username@hostname' 2024-12-26 12:34:56
This example returns both the system user and the current timestamp.
Usage Notes
- If you need to check the user information for auditing or debugging purposes,
SYSTEM_USER()is useful. - It can return different results based on how the user connected to the MySQL server, especially in cases of multiple authentication methods or different host connections.