44

I have multiple text console session open and log in as different users into different consoles. I forget after while which consoles belong to which user, it would be nice to not have to quit and log back in.

How do I see which user I am logged in as?

Is there a way to change which user I logged in as with out logging out?

fixer1234
  • 27,064
  • 61
  • 75
  • 116
nelaaro
  • 13,149
  • 30
  • 84
  • 111

4 Answers4

55

Actually, you need to use two functions

SELECT USER(),CURRENT_USER();

USER() reports how you attempted to authenticate in MySQL

CURRENT_USER() reports how you were allowed to authenticate in MySQL

Sometimes, they are different

RolandoMySQLDBA
  • 3,065
  • 1
  • 20
  • 25
  • eg. if you login to mysql via `mysql -ulalala` where `lalala` user doesn't exist, you will be allowed to login as 'anonymous' mysql user, namely `''@'localhost'`. In this case returns of functions would be `USER()= lalala@localhost` and `CURRENT_USER() = @localhost` – Dimitry K Jan 27 '15 at 14:23
  • 2
    @DimitryK When that happens, you can run `SHOW GRANTS;` to see what permissions you have. Even if you see nothing except `USAGE`, you still need to be aware that certain test databases are 100% accessible to an anonymous user. See my post `MySQL : Why are there “test” entries in mysql.db?` (http://dba.stackexchange.com/q/13361/877) – RolandoMySQLDBA Jan 27 '15 at 14:38
  • +1 for `SHOW GRANTS`, strange that I haven't stumbled upon it though reading numerous Mysql Tutorials. – Dimitry K Jan 27 '15 at 15:18
2

I found this user() function

select user(); Will show you which user is logged in.

nelaaro
  • 13,149
  • 30
  • 84
  • 111
  • Does that link still work for you? I decided to link to google's cache because of the mysql -> oracle breakage. – Pricey Apr 05 '11 at 08:00
  • It does work, it has an other interesting function as well select database(); will show you your currently selected database. – nelaaro Apr 05 '11 at 08:07
  • That's really annoying, I wonder why it doesn't work for me. Thanks. – Pricey Apr 05 '11 at 08:08
  • @pricechild http://dev.mysql.com/doc/refman/5.5/en/information-functions.html#function_user – nelaaro Apr 05 '11 at 08:21
  • Nope, sends me to http://search.oracle.com/search/search?q=information-functions.html&group=MySQL#function_user – Pricey Apr 05 '11 at 08:30
  • @pricechild which browser are you using. I use google chrome it works perfectly. I wander where the redirection is coming from. – nelaaro Apr 05 '11 at 08:35
2

You can use 'status':

MariaDB [my_database]> status

Current user: root@localhost

JohnW.
  • 21
  • 2
1

Does

select user();

work?

I pinched it from the 3rd google result for 'mysql whoami':

Pricey
  • 4,632
  • 2
  • 24
  • 32