Is there a way to know your current username in MySQL?


Yes, you can use the method CURRENT_USER() to know the current username in MySQL.

The above method returns the username that can be used to authenticate the client connection.

The query is as follows −

mysql> select CURRENT_USER();

The following is the output −

+----------------+
| CURRENT_USER() |
+----------------+
| root@%         |
+----------------+
1 row in set (0.00 sec)

Or you can use USER() method from MySQL. The query is as follows −

mysql> select user();

Here is the output −

+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)

Updated on: 30-Jul-2019

7K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements