1 软件环境
CentOS7、MySQL5.8及以下
2 登录问题
(1) ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
(2) ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
(3) ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this ...
3 原因
MySQL有默认密码,登录时未获取默认密码,从而报错。
4 解决方案
4.1 无密码登录
(1) 进入用户配置:#vim /etc/my.cnf;
(2) 在mysql后添加skip-grant-tables,如图4.1所示(vim状态下可以直接搜索,搜索:mysqld);
图4.1 添加跳过密码指令
(3) 重启&登录
①mysql service restart
②mysql enter
4.2 更改密码登录
(1) 查看原始密码
sudo grep 'temporary password' /var/log/mysqld.log
(2) 密码要求
① At least one upper case letter(至少一个大写字母)
② At least one lower case letter, one digit(至少一个小写字母和一个数字)
③ At least one special character(至少一个特殊字符)
④ The total password length is at least 8 characters(密码长度至少8位)
(3) 设置密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'your password',如图4.2所示;
图4.2 修改密码指令
(4) 密码登录
① mysql -u root -p
② password: your password