how do I see which user I am logged in as in MySQL?

60,444

Solution 1

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

Solution 2

I found this user() function

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

Solution 3

You can use 'status':

MariaDB [my_database]> status

Current user: root@localhost

Solution 4

Does

select user();

work?

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

Share:
60,444

Related videos on Youtube

nelaaro
Author by

nelaaro

Linux admin, tech enthusiast. opensource evangelist.

Updated on September 18, 2022

Comments

  • nelaaro
    nelaaro over 1 year

    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?

  • Pricey
    Pricey about 13 years
    Does that link still work for you? I decided to link to google's cache because of the mysql -> oracle breakage.
  • nelaaro
    nelaaro about 13 years
    It does work, it has an other interesting function as well select database(); will show you your currently selected database.
  • Pricey
    Pricey about 13 years
    That's really annoying, I wonder why it doesn't work for me. Thanks.
  • Pricey
    Pricey about 13 years
    Nope, sends me to search.oracle.com/search/…
  • nelaaro
    nelaaro about 13 years
    @pricechild which browser are you using. I use google chrome it works perfectly. I wander where the redirection is coming from.
  • Dimitry K
    Dimitry K over 9 years
    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
    Dimitry K over 9 years
    +1 for SHOW GRANTS, strange that I haven't stumbled upon it though reading numerous Mysql Tutorials.