Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to know your current username in mysql?

Tags:

mysql

I would like to know if there's a way for a mysql query to return the username of the user that issues the query.

Is this possible?

like image 238
user1090729 Avatar asked Oct 13 '13 21:10

user1090729


People also ask

How do I find my MySQL username?

MySQL CURRENT_USER() Function The CURRENT_USER() function returns the user name and host name for the MySQL account that the server used to authenticate the current client. The result is returned as a string in the UTF8 character set. Tip: See also the USER() function.

How do I find my MySQL username and password?

So for example, to show MySQL users' username, password and host, we'll modify the sql query to accordingly as such: mysql> select user, password, host from mysql. user; The above sql query will present you with a list of users and their respective user name, password and database host.


2 Answers

Try to run either

SELECT USER(); 

or

SELECT CURRENT_USER(); 

It can sometimes be different, USER() will return by which login you attempted to authenticate and CURRENT_USER() will return how you were actually allowed to authenticate.

like image 80
Petr Mensik Avatar answered Oct 14 '22 07:10

Petr Mensik


Try the CURRENT_USER() function. This returns the username that MySQL used to authenticate your client connection. It is this username that determines your privileges.

This may be different from the username that was sent to MySQL by the client (for example, MySQL might use an anonymous account to authenticate your client, even though you sent a username). If you want the username the client sent to MySQL when connecting use the USER() function instead.

The value indicates the user name you specified when connecting to the server, and the client host from which you connected. The value can be different from that of CURRENT_USER().

http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_current-user

like image 23
scotru Avatar answered Oct 14 '22 06:10

scotru