Check the current user in MySQL command line

37.2k Views Asked by At

Here is my question about MySQL.

After I log in to MySQL using:

mysql -u myname -p
...
mysql>

I wanted to know what the username I used to logon. Is there a way to check this? like "whoami" in unix?

Thanks.

2

There are 2 best solutions below

2
On BEST ANSWER

There is a MYSQL function user(). To get the user:

SELECT USER();

This will return something like username@hostname.

0
On

You can show the current user with CURRENT_USER(), CURRENT_USER or USER() as shown below. *My answer also explains the difference between CURRENT_USER() or CURRENT_USER and USER():

SELECT CURRENT_USER();

Or:

SELECT CURRENT_USER;

Or:

SELECT USER();