Centos 下初次登录mysql密码错误

mysql5.7初次登录报错(命令行安装会生成随机密码)
mysql安装成功后创建的超级用户'root'@'localhost'的密码会被存储在/var/log/mysqld.log
查看方法:

grep 'temporary password' /var/log/mysqld.log

登录还报错的话
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passwor)问题

先关掉服务器
service mysqld stop

1.vim /etc/my.cnf
2.在[mysqld]中添加
skip-grant-tables
例如:
[mysqld]
skip-grant-tables
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
3.重启mysql
service mysqld restart
4.用户无密码登录
mysql -uroot -p (直接点击回车,密码为空)
5.选择数据库
use mysql;
6.修改root密码

update mysql.user set authentication_string=password('新密码') where user='用户';

7.执行
 flush privileges;
8.退出 mysql
quit
9.编辑 /etc/my.cnf 
删除 skip-grant-tables  保存退出
10.重启mysql
service mysqld restart

错误2: ERROR 1819 (HY000): You must reset your password using ALTER USER statement before executing this statement.
解决方法:

> set global validate_password_policy=0;
   注意新的密码不能太简单
> SET PASSWORD = PASSWORD('your new password'); 

> ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
> flush privileges;
然后退出 重新登录就行了 

你可能感兴趣的:(Centos 下初次登录mysql密码错误)