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

36

11

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?

nelaaro

Posted 2011-04-05T07:51:14.407

Reputation: 9 321

Answers

45

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

Posted 2011-04-05T07:51:14.407

Reputation: 2 675

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 – 2015-01-27T14:23:11.320

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 – 2015-01-27T14:38:21.593

+1 for SHOW GRANTS, strange that I haven't stumbled upon it though reading numerous Mysql Tutorials. – Dimitry K – 2015-01-27T15:18:26.887

2

I found this user() function

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

nelaaro

Posted 2011-04-05T07:51:14.407

Reputation: 9 321

Does that link still work for you? I decided to link to google's cache because of the mysql -> oracle breakage. – Pricey – 2011-04-05T08:00:52.983

It does work, it has an other interesting function as well
select database(); will show you your currently selected database.
– nelaaro – 2011-04-05T08:07:13.137

That's really annoying, I wonder why it doesn't work for me. Thanks. – Pricey – 2011-04-05T08:08:12.370

@pricechild which browser are you using. I use google chrome it works perfectly. I wander where the redirection is coming from. – nelaaro – 2011-04-05T08:35:29.020

1

Does

select user();

work?

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

Pricey

Posted 2011-04-05T07:51:14.407

Reputation: 4 262

0

You can use 'status':

MariaDB [my_database]> status

Current user: root@localhost

JohnW.

Posted 2011-04-05T07:51:14.407

Reputation: 1