centos7 上安装mysql5.7后登录报错ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using pas
安装完mysql后会有个临时密码去日志查看,但是查看登录修改密后还是不行
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password:yes)
于是
1,停止mysql服务
systemctl stop mysqld.service
2,修改配置文件无密码登录
[html] view plain copy
- vi /etc/my.cnf
在最尾部加上
[html] view plain copy
- skip-grant-tables
保存
3,启动mysql
[html] view plain copy
- systemctl start mysqld.service
4,登录musql
[html] view plain copy
- mysql -u root
此处注意不要加-p
5,修改密码,mysql5.7用此语法
[html] view plain copy
- use mysql ;
[html] view plain copy
- update mysql.user set authentication_string=password('123456') where user='root' ;
6,回到第二步骤去掉加上的
[html] view plain copy
- skip-grant-tables
保存 重启mysql就ok了
#########################################################################
其实默认安装完了mysql后或在日志中生成一个默认的密码 /var/log/mysqld.log 中
拿到默认密码后登录mysql 进行密码重新设置
[html] view plain copy
- set passwprd=password('you password');
如果密码级别与默认的级别要求不符时候会报
[html] view plain copy
- Your password does not satisfy the current policy requirements
此时需要修改级别与最小的默认密码位数
[html] view plain copy
- set global validate_password_policy=0;
- set global validate_password_length=4;
然后在进行设置密码就好了
###################
远程连接时1130错误
[html] view plain copy
- mysql;use mysql;
- mysql;select 'host' from user where user='root';
- mysql;update user set host = '%' where user ='root';
- mysql;flush privileges;
- mysql;select 'host' from user where user='root';