重裝 MySQL 後,root 密碼輸入正確仍報 ERROR 1045 (28000): Access denied for user 'root'@'localhost'。
mysql.user 表,密碼雜湊不匹配skip-grant-tables 未生效service mysqld stopvi /etc/my.cnf,在 [mysqld] 下加 skip-grant-tablesservice mysqld start(無需密碼直接進)mysql -u root
USE mysql;
UPDATE user SET authentication_string=PASSWORD('NewPass123!') WHERE user='root';
FLUSH PRIVILEGES;
MySQL 5.7+ 用 authentication_string,5.6 用 password。
vi /etc/my.cnf 刪除該行 → service mysqld restartmysql -u root -p'NewPass123!'SELECT host, user FROM mysql.user;
-- 僅有 localhost?遠程需 '%' 或具體 IP
UPDATE user SET host='%' WHERE user='root';
FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'NewPass123!';
DELETE FROM mysql.user WHERE user='';DELETE FROM mysql.user WHERE user='root' AND host='%';DROP DATABASE test; DELETE FROM mysql.db WHERE db='test' OR db='test\_%';FLUSH PRIVILEGES;