Linux MySQL的root没法登陆数据库ERROR 1045 (28000)

Linux环境下,脚本自动安装完数据库,命令行用mysql -uroot -ppasswaord 登陆却报了这么个错:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)mysql

网上解决办法都差很少,大概作个整理吧:
一、编辑/etc/my.cnf添加skip-grant-tables
二、重启MySQL服务(Linux版本不一样可能命令略不同)
systemctl restart mysqld.service
三、修改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;
四、注释掉skip-grant-tables
五、重启MySQL服务
六、mysql -uroot -p我是密码
此时能登陆上去,但可能其余大部分操做都会报错
七、ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
则再设一次密码便可
SET PASSWORD = PASSWORD('我是密码');
八、若报错:ERROR 1819 (HY000): Your password does not satisfy the current policy requirements则修改密码策略,再修改密码。
mysql> set global validate_password_policy=low;
九、登陆验证是否能成功登陆,并尝试其余操做验证帐户是否正常sql

相关文章
相关标签/搜索