Is there any way to find out your current username in mysql?

I would like to know if there is a way for the mysql query to return the username of the user who issues the query.

Is it possible?

+61
mysql
Oct 13 '13 at
source share
7 answers

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

This may differ from the username that was sent to the client in MySQL (for example, MySQL may use an anonymous account to authenticate your client, even if you sent the username). If you want the username that the client sent to MySQL when connecting, use the USER() function instead.

The value indicates the username that you provided when connecting to the server, and the client host from which you connected. The value may differ from the value of CURRENT_USER ().

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

+54
Oct 13 '13 at 21:07 on
source share

Try to run

 SELECT USER(); 

or

 SELECT CURRENT_USER(); 

Sometimes it can be otherwise, USER () will return with the help of which you tried to authenticate and CURRENT_USER () will return, as authentication was really allowed to you.

+63
Oct 13 '13 at 21:08
source share

Use this query:

 SELECT USER(); 

or

 SELECT CURRENT_USER; 
+16
Oct 13 '13 at 21:07 on
source share

You can use:

 SELECT USER(); 

or

 SELECT CURRENT_USER(); 

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

+7
Oct 13 '13 at 21:08
source share

to print the current user who is using the database

 select user(); 

or

 select current_user(); 
+2
Feb 01 '16 at 4:17
source share

You can also use: mysql> select user, host from mysql.user;

 +---------------+-------------------------------+ | user | host | +---------------+-------------------------------+ | fkernel | % | | nagios | % | | readonly | % | | replicant | % | | reporting | % | | reporting_ro | % | | nagios | xx.xx.xx.xx | | haproxy_root | xx.xx.xx.xx | root | 127.0.0.1 | | nagios | localhost | | root | localhost | +---------------+-------------------------------+ 
+2
Oct 19 '16 at 19:24
source share

You can find the current username using the CURRENT_USER () function in MySQL.

For example: SELECT CURRENT_USER();

But CURRENT_USER() does not always return the registered user. So if you want the user to log in, use SESSION_USER() instead.

0
Dec 14 '18 at 8:07
source share



All Articles