一、mysql忘记root密码?
1.编辑mysql配置文件my.cnf
vi /etc/my.cnf
2.添加代码到图中位置
skip-grant-tables
#保存退出
1.ESC 2. : (英文冒号)
3.wq
3. 重启mysql服务
service mysqld restart
4.进入mysql
mysql -uroot -p
#直接按回车不用输入密码
5.修改密码
update mysql.user set authentication_string=password('123456') where User="root" and Host="localhost";
6.刷新系统授权表
flush privileges;
7.权限修改
grant all on *.* to 'root'@'localhost' identified by '123456' with grant option;
#此时可以本地localhost登录运行
8.删除my.cnf中添加的代码
删除这一行
#保存退出
1.ESC 2. : (英文冒号)
3.wq
9.重启mysql服务
service mysqld restart
10.进入mysql服务
mysql -uroot -p
#此时密码就是123456
此时mysql服务就可以正常使用密码登录
二、数据库连接1045(密码正确)
####忘记密码参考目录一
####(密码正确)由于没有授予远程登录权限
1.进入mysql
mysql -uroot -p
2.进入user表
use mysql
3.授权远程登录
grant all on *.* to root@'%' identified by '123456';
#如果此处未报错,则进行第七步
4.调整validate_password_policy 等级为0
set global validate_password_policy=0;
5.修改密码长度为1
set global validate_password_length=1;
###再次执行第三部
6.刷新一下
flush privileges;
7.重启mysql服务
service mysqld restart
####可以远程登录了