If you've set a password for the root user in MySQL but it's not working, the issue could be related to the multiple root
user entries with different host specifications (127.0.0.1
, ::1
, localhost
). Hereβs what could be causing the problem and how to fix it:
π Possible Reasons and Fixes
1οΈβ£ Password Not Set for All root
Entries
Since MySQL treats root@localhost
, root@127.0.0.1
, and root@::1
as separate users, the password may only be set for one of them while others still have no password.
π Check which root
users have passwords:
SELECT user, host, authentication_string FROM mysql.user WHERE user = 'root';
If any of them have an empty authentication_string
, they are using no password.
π Set password for all root users:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'YourNewPassword';
ALTER USER 'root'@'127.0.0.1' IDENTIFIED BY 'YourNewPassword';
ALTER USER 'root'@'::1' IDENTIFIED BY 'YourNewPassword';
FLUSH PRIVILEGES;
2οΈβ£ MySQL Authentication Plugin Issue
MySQL allows users to authenticate using different plugins like mysql_native_password
or caching_sha2_password
. Some versions of XAMPP (with MariaDB) default to auth_socket
, which allows root login without a password.
π Check the authentication plugin used by root:
SELECT user, host, plugin FROM mysql.user WHERE user = 'root';
If you see auth_socket
, your MySQL is configured to allow login only via Unix socket (without a password).
π Fix it by setting the plugin to mysql_native_password
:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YourNewPassword';
ALTER USER 'root'@'127.0.0.1' IDENTIFIED WITH mysql_native_password BY 'YourNewPassword';
ALTER USER 'root'@'::1' IDENTIFIED WITH mysql_native_password BY 'YourNewPassword';
FLUSH PRIVILEGES;
3οΈβ£ You're Using the Wrong Host
If you are logging in using mysql -u root -p
, MySQL might be trying root@localhost
, but your password is set for root@127.0.0.1
.
π Try logging in explicitly using different hosts:
mysql -u root -p -h 127.0.0.1
mysql -u root -p -h localhost
mysql -u root -p -h ::1
If one works but the others donβt, you know which user entry needs fixing.
4οΈβ£ MySQL Server Not Restarted After Password Change
Sometimes, changes require a MySQL restart.
π Restart MySQL (XAMPP) and Try Again:
- Stop MySQL from the XAMPP control panel.
- Start it again.
- Try logging in.
5οΈβ£ FLUSH PRIVILEGES Not Run
If you've changed the password but didnβt run FLUSH PRIVILEGES;
, the new password may not be applied.
π Run this command in MySQL:
FLUSH PRIVILEGES;
π₯ Final Fix: Reset Root Password
If nothing works, reset the root password manually:
- Stop MySQL from XAMPP.
- Open a terminal/command prompt and start MySQL in safe mode:
mysqld --skip-grant-tables --skip-networking
- Open another terminal and log in without a password:
mysql -u root
- Reset the password:
UPDATE mysql.user SET authentication_string = PASSWORD('YourNewPassword') WHERE user = 'root';
FLUSH PRIVILEGES;
- Restart MySQL and try logging in.
β
Summary of Fixes
β Check if password is set for all root
entries (localhost
, 127.0.0.1
, ::1
).
β Ensure MySQL authentication plugin is mysql_native_password
.
β Try logging in with different hosts (127.0.0.1
, localhost
, ::1
).
β Restart MySQL after changing the password.
β Run FLUSH PRIVILEGES;
to apply changes.
β If all else fails, reset the password manually.
Try these steps and let me know if you need further help! π