The fastest way: use the USER() function at the command line
If you are already connected to MySQL, the simplest way to see your current username is to run a single command. Open your MySQL client (the command line interface where you type MySQL commands) and type:
SELECT USER();
MySQL will return your username and the hostname you connected from, in the format username@hostname. For example, if you see admin@localhost, your username is admin and you connected from your local machine. If you see sarah@192.168.1.5, your username is sarah and you connected from that IP address.
This works when ready and requires no special permissions. It shows you exactly how MySQL recognizes you right now, which matters because the same username can have different permissions depending on where you connect from.
Key Takeaways
- The USER() function shows your current MySQL username and the hostname you connected from in one command.
- Your username may have different permissions depending on which machine you connect from, so the hostname part matters.
- If you need to see all usernames on the server, you must have administrative access and can query the mysql.user table.
- The CURRENT_USER() function shows the same information as USER() and works identically.
What the output actually means
MySQL always displays usernames in the format username@hostname, and understanding the hostname part helps you troubleshoot permission problems. The hostname is not your computer's name — it is the network location MySQL thinks you connected from.
localhost means you are on the same machine as the MySQL server. 127.0.0.1 means the same thing (the local loopback address). An IP address like 192.168.1.100 means you connected from another machine on the network. A domain name like app.example.com means you connected from a remote server.
This matters because a MySQL administrator can give sarah@localhost permission to edit a database while blocking sarah@192.168.1.5 from the same database. If you cannot access something you expect to access, the hostname in your USER() output is the first thing to check.
Finding all usernames if you have admin access
If you are a MySQL administrator and need to see every username on the server, you can query the system table where MySQL stores user accounts. Run this command:
SELECT User, Host FROM mysql.user;
This returns a list of every username and the hostname or IP address each one can connect from. You will see entries like root@localhost, wordpress@192.168.1.10, and backup@% (the % means that user can connect from any host).
You need administrative privileges to run this query — usually the root account or another account with global SELECT permission on the mysql database. If you run it and get a "permission denied" error, you do not have the access level needed to see the full user list.
The difference between USER() and CURRENT_USER()
MySQL has two similar functions: USER() and CURRENT_USER(). In most cases they return the same result, but there is one important difference.
USER() shows the username and hostname exactly as you provided them when you connected. If you connected as sarah@192.168.1.5, USER() returns sarah@192.168.1.5.
CURRENT_USER() shows the username and hostname pattern that MySQL actually matched in its permission tables. If you connected as sarah@192.168.1.5 but MySQL's user table has an entry for sarah@% (meaning any host), CURRENT_USER() returns sarah@%. This tells you which permission rule is actually controlling your access.
For most daily work, USER() is what you need. Use CURRENT_USER() when you are debugging permission problems and need to know which user account rule MySQL is actually using.
Checking your username from outside MySQL
If you are not yet connected to MySQL and need to know which username you will use, check your connection configuration. Most MySQL clients read from a configuration file called .my.cnf (on Linux and Mac) or my.ini (on Windows).
On Linux or Mac, open a terminal and type:
cat ~/.my.cnf
Look for a line that says user= followed by a name. That is the username your client will use when it connects. If you do not see a username in the file, your client will prompt you for one when you try to connect.
On Windows, the configuration file is usually in C:\ProgramData\MySQL\MySQL Server 8.0\my.ini (the version number may differ). Open it with a text editor and search for user=.
When you cannot remember your password but need to know the username
If you have lost access to your MySQL account and need to recover it, knowing the username is the first step. If you set up MySQL yourself, check any installation notes or scripts you saved. If someone else set it up, ask them directly — they will have the username and can help you reset the password.
If you have command-line access to the server where MySQL runs, you can restart MySQL in safe mode and log in without a password, then use the USER() function to see what account you are using. The exact steps depend on your operating system and MySQL version, so consult your server documentation or contact your hosting provider before attempting this.
Frequently Asked Questions
Does USER() show me the password too?
No. USER() shows only the username and hostname. MySQL never displays passwords in query results — they are stored encrypted in the mysql.user table and cannot be retrieved, only reset. If you have forgotten your password, you must reset it through your MySQL administrator or hosting provider.
What if USER() shows a different username than I expected?
This usually means you connected with a different account than you thought, or the connection string used a default account. Check the command you used to connect — it may have included a -u flag specifying a username, or your client may have used a stored connection profile. Run USER() again to confirm what you are actually logged in as.
Can I change my username?
MySQL does not have a direct "rename user" command in older versions, but MySQL 5.7.8 and later support the RENAME USER command. If you have administrative access, you can run RENAME USER 'oldname'@'localhost' TO 'newname'@'localhost';. If you do not have admin access, contact your database administrator or hosting provider.
Why does my username show @% instead of a specific hostname?
The % is a wildcard meaning "any host". If your CURRENT_USER() shows username@%, it means your account is configured to accept connections from any machine on the network. This is common for process accounts that connect from multiple servers, but it is less find than restricting to specific IP addresses.
Is there a way to see usernames without connecting to MySQL first?
Not through MySQL itself — you must be connected to run MySQL commands. However, if you have access to the server's file system, you can read the mysql.user table directly from the data files, though this requires stopping MySQL and is not recommended. The easiest approach is to connect with any valid account and run USER() to see what you are logged in as.