Linux環境下,腳本自動安裝完數據庫,命令行用mysql -uroot -ppasswaord 登錄卻報了這么個錯:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
網上解決辦法都差不多,大概做個整理吧:
1、編輯/etc/my.cnf添加skip-grant-tables
2、重啟MySQL服務(Linux版本不同可能命令略不一樣)
systemctl restart mysqld.service
3、修改MySQL密碼(以下兩條命令執行一條即可,根據MySQL版本選擇,后一個適合版本比前一個高)
update user set password=password('我是密碼') where user='root' and host='localhost';
update user set authentication_string=password('我是密碼') where user='root' and host='localhost';
FLUSH PRIVILEGES;
4、注釋掉skip-grant-tables
5、重啟MySQL服務
6、mysql -uroot -p我是密碼
此時能登錄上去,但可能其他大部分操作都會報錯
7、ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
則再設一次密碼即可
SET PASSWORD = PASSWORD('我是密碼');
8、若報錯:ERROR 1819 (HY000): Your password does not satisfy the current policy requirements則修改密碼策略,再修改密碼。
mysql> set global validate_password_policy=low;
9、登錄驗證是否能成功登錄,並嘗試其他操作驗證賬戶是否正常