MySQL CURRENT_USER() Function

The CURRENT_USER() function in MySQL provides a simple way to identify the currently connected user and their host.



CURRENT_USER(): Definition and Usage

This function is quite useful for security, auditing, and debugging. It retrieves the MySQL user account used by the server to authenticate the current client connection. The returned information includes both the username and the hostname from where the connection originated. The result is always a string encoded in UTF8.

Equivalent Functions

CURRENT_USER() is equivalent to both SESSION_USER() and USER(). All three functions provide the same information about the active user and connection.

Syntax

Syntax

CURRENT_USER()
      

Example

Retrieving User and Host Information

This query demonstrates how to use CURRENT_USER() to get the username and hostname.

Syntax

SELECT CURRENT_USER();
      
Output

'your_username'@'your_hostname'  (Example: 'admin'@'localhost')
      

**Note:** Replace `'your_username'@'your_hostname'` with the actual output you see when you run the query. The username and hostname are returned as a single string, separated by the "@" symbol. The exact output depends on your MySQL server configuration and your current connection.