1. View the MySQL username
Method 1: Use the command line
Open Command Prompt (CMD)
-
Win + R,enter
cmd
, press Enter. - (If MySQL wants administrator permissions) Right-click CMD and select "Run as administrator"。
Log in MySQLIf you still remember the MySQL password:
mysql -u root -p
If no password is set,try:
mysql -u root
Query all MySQL users
SELECT User, Host FROM ;
Common usernames:
- root(Super Administrator)
- mysql(Some versions default users)
- admin(Some systems default users)
2. View MySQL password (encrypted storage, cannot be viewed directly)
MySQL does not allow direct viewing of passwords, but you can check whether the password is empty:
SELECT User, authentication_string FROM ;
ifauthentication_string
If empty, it means that the user does not have a password.
3. Reset MySQL Password
Method 1: Use the command line to reset the root password
If you cannot log in to MySQL, you can use itSkip permission table modeReset password:
Step 1: Stop MySQL
Windows (Admin CMD Running):
net stop mysql
Linux/macOS:
sudo systemctl stop mysql
Step 2: Start MySQL (Skip permission verification)
mysqld --skip-grant-tables --skip-networking
This mode allows direct login without requiring a password.
Step 3: Reopen a terminal and log in to MySQL
mysql -u root
Step 4: Modify the password
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password'; FLUSH PRIVILEGES;
replacenew_password
For your new password.
Step 5: Restart MySQL
net stop mysql net start mysql
or:
sudo systemctl restart mysql
Then you can log in with your new password:
mysql -u root -p
Method 2: Modify the configuration file directly
- Open
(Windows is usually in
C:\ProgramData\MySQL\MySQL Server 8.0\
)。 - exist
[mysqld]
Added to the paragraph:
skip-grant-tables
Save the file and restart MySQL:
net stop mysql net start mysql
Then usemysql -u root
Log in, reset password:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password'; FLUSH PRIVILEGES;
Finally, deleteskip-grant-tables
And restart MySQL.
Summarize
✅ View MySQL Users:
SELECT User, Host FROM ;
✅ If you forget your password, reset your password:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password'; FLUSH PRIVILEGES;
✅ If you cannot log in, use--skip-grant-tables
Mode reset password.
This is the end of this article about MySQL viewing local username and password. For more related mysql viewing username and password content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!