CentOS 7 Minimal下修改Root密码后无法访问MySQL 8.0求助
Hey, let's figure out why you can't log in after changing the MySQL root password on CentOS 7 Minimal. I've run into this exact issue a few times, and it's almost always one of these two common pitfalls:
1. Your new password got mangled by the shell (most likely)
Looking at your command:
mysqladmin -u root -p'Pass-123***' password Myp@$$123
The problem here is the $$ in your new password. In bash, $$ is a special variable that gets replaced with the current shell's process ID. That means the password you actually set isn't Myp@$$123 — it's Myp@[some-random-number]123. No wonder you can't log in with the password you intended!
To fix this, wrap your new password in single quotes (which prevent shell variable expansion) when running mysqladmin:
mysqladmin -u root -p'Pass-123***' password 'Myp@$$123'
2. mysqladmin might not play nicely with MySQL 8.0's default auth plugin
MySQL 8.0 uses caching_sha2_password as the default authentication plugin, and while mysqladmin should handle it, sometimes using the SQL ALTER USER command directly is more reliable. Here's how to reset your password that way (in case the first fix doesn't work):
- Stop the MySQL service first:
systemctl stop mysqld - Start MySQL with skip-grant-tables to bypass password checks (add
--skip-networkingto block unauthorized remote access during this process):mysqld_safe --skip-grant-tables --skip-networking & - Log into MySQL without a password:
mysql -u root - Switch to the
mysqldatabase (where user credentials are stored):USE mysql; - Update the root user's password (keep the quotes inside the SQL statement to preserve special characters):
If you need compatibility with older clients, you can specify theALTER USER 'root'@'localhost' IDENTIFIED BY 'Myp@$$123';mysql_native_passwordplugin instead:ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Myp@$$123'; - Flush privileges to apply the changes immediately:
FLUSH PRIVILEGES; - Exit the MySQL shell:
EXIT; - Stop the temporary mysqld_safe process:
pkill mysqld - Start MySQL normally:
systemctl start mysqld
Now try logging in again with:
mysql -u root -p
Enter your new password Myp@$$123 — it should work this time.
内容的提问来源于stack exchange,提问作者TheBIGBILL

