MySQL SYSTEM_USER() Function
MySQL SYSTEM_USER() Function
The MySQL SYSTEM_USER() function returns the username and hostname of the client session currently connected to the MySQL server. In MySQL, SYSTEM_USER() is a synonym for USER() and SESSION_USER().
Syntax
SYSTEM_USER()
- Takes zero arguments and returns a
VARCHARformatted asuser_name@host_name.
The function exists primarily for ODBC and SQL standard compatibility across database engines, returning the client-supplied account identity rather than the OS process owner running mysqld.
Practical Example
Include SYSTEM_USER() in an administrative diagnostic query when verifying which container or developer workstation opened a database connection.
SELECT
SYSTEM_USER() AS connected_client,
CONNECTION_ID() AS thread_id,
VERSION() AS mysql_version;
| connected_client | thread_id | mysql_version |
|---|---|---|
| admin_cli@192.168.1.44 | 1924 | 8.0.39 |
Common Mistakes & NULL Behavior
- NULL behavior:
SYSTEM_USER()takes zero parameters and never returnsNULLduring a live connection. Passing any argument (includingNULL) produces anIncorrect parameter counterror. - Does not return OS user: Despite the name "system user", it does not return the Linux or Windows OS user account running your app or the MySQL server; it returns the MySQL client login string.
- Not the MySQL
SYSTEM_USERprivilege: MySQL 8.0 added a dynamic privilege namedSYSTEM_USERto protect admin accounts. That privilege is completely unrelated to theSYSTEM_USER()SQL function. - No-paren call fails: Writing
SELECT SYSTEM_USER;fails with an unknown column error; always include().
Frequently Asked Questions
What is the difference between SYSTEM_USER() and USER() in MySQL?
They behave identically in MySQL. Both return the user_name@host_name supplied by the connecting client.
Does SYSTEM_USER() tell me the Linux user running MySQL?
No. It returns the MySQL client account and client host/IP, never the operating system user.
Why use SYSTEM_USER() instead of CURRENT_USER()?
Use SYSTEM_USER() to see the exact client host/IP or caller identity inside a DEFINER view; use CURRENT_USER() to see the matched privilege grant.
Unlock Your
Full Potential.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Try it Yourself
Experiment with the code from this lesson in our interactive playground.