Collections:
USER() - Login Name of Current User
How to obtain the login name of the current user using the USER() function?
✍: FYIcenter.com
USER() is a MySQL built-in function that returns the login name of the current user. Login name is defined as the combination of user name and the client IP address where you logged in from. For example:
SELECT USER(); -- +------------------+ -- | USER() | -- +------------------+ -- | fyi@192.168.1.11 | -- +------------------+
Note that the related CURRENT_USER() function returns the authentication name of user, which is a combination of "User" and "Host" columns in the mysql.user table and used to authenticate you into the system. So the authentication name returned from CURRENT_USER() may differ from the login name returned by USER(). For example:
SELECT USER(), CURRENT_USER(); -- +------------------+----------------+ -- | USER() | CURRENT_USER() | -- +------------------+----------------+ -- | fyi@192.168.1.11 | fyi@% | -- +------------------+----------------+ SELECT User, Host, authentication_string FROM mysql.user WHERE User = 'fyi'; -- +------+-----------+-------------------------------------------+ -- | User | Host | authentication_string | -- +------+-----------+-------------------------------------------+ -- | fyi | % | *94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29 | -- | fyi | localhost | *3735F1D8464342BA852E10101E55E422EBAAAF35 | -- +------+-----------+-------------------------------------------+
Reference information of the USER() function:
USER(): user Returns the login name of the current user. Arguments, return value and availability: user: Return value. The login name of the current user. Available since MySQL 4.0.
Related MySQL functions:
⇒ VERSION() - Version Number of MySQL Server
⇐ SYSTEM_USER() - Synonym for USER()
2023-12-19, 237🔥, 0💬
Popular Posts:
How To Convert Binary Strings into Integers in SQL Server Transact-SQL? Binary strings and integers ...
How To Update Multiple Rows with One UPDATE Statement in SQL Server? If the WHERE clause in an UPDAT...
How REAL and FLOAT Literal Values Are Rounded in SQL Server Transact-SQL? By definition, FLOAT(n) sh...
How To Use "IF ... ELSE IF ..." Statement Structures in SQL Server Transact-SQL? "IF ... ELSE IF ......
What Happens to Your Transactions When ERROR 1205 Occurred in MySQL? If your transaction receives th...