Collections:
CURRENT_USER() - Authentication Name of Current User
How to obtain the authentication name of the current user using the CURRENT_USER() function?
✍: FYIcenter.com
CURRENT_USER() is a MySQL built-in function that
returns the authentication name of the current user.
The authentication name is a combination of "User" and "Host"
columns in the mysql.user table and used to authenticate you
into the system.
For example:
SELECT CURRENT_USER(); -- +----------------+ -- | CURRENT_USER() | -- +----------------+ -- | fyi@% | -- +----------------+ SELECT User, Host, authentication_string FROM mysql.user WHERE User = 'fyi'; -- +------+-----------+-------------------------------------------+ -- | User | Host | authentication_string | -- +------+-----------+-------------------------------------------+ -- | fyi | % | *94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29 | -- | fyi | localhost | *3735F1D8464342BA852E10101E55E422EBAAAF35 | -- +------+-----------+-------------------------------------------+
Note that the related USER() function returns the login name of user, which is the combination of user name and the client IP where you logged in from. So the login name returned from USER() may differ from the authentication name returned by CURRENT_USER(). For example:
SELECT USER(), CURRENT_USER(); -- +------------------+----------------+ -- | USER() | CURRENT_USER() | -- +------------------+----------------+ -- | fyi@192.168.1.11 | fyi@% | -- +------------------+----------------+
Reference information of the CURRENT_USER() function:
CURRENT_USER(): user Returns the authentication name of the current user. Arguments, return value and availability: user: Return value. The authentication name of the current user. Available since MySQL 4.0.
Related MySQL functions:
⇒ DATABASE() - Name of Current Database
⇐ CURRENT_ROLE() - Current Role of Logged-In User
2025-06-18, 1645🔥, 0💬
Popular Posts:
How to set database to be READ_ONLY in SQL Server? Databases in SQL Server have two update options: ...
How To Convert Numeric Values to Integers in SQL Server Transact-SQL? Sometimes you need to round a ...
How To List All Stored Procedures in the Current Database in SQL Server Transact-SQL? If you want to...
Why I Can Not Enter 0.001 Second in DATETIME values in SQL Server Transact-SQL? If you enter millise...
How to put statements into a statement block in SQL Server Transact-SQL? You can put statements into...