MySQL登录时出现Access denied

1、到安装的MySQL的目录下,找 /etc/my.cnf 文件

在[mysqld]后添加 skip-grant-tables(使用 set password for设置密码无效,且此后登录无需键入密码)

 

重启mysql服务

service mysqld restart

2、登录mysql,键入mysql –uroot –p;直接回车(Enter)

 

 键入无效 set password for ‘root’@‘localhost’=password(‘123456’); 会报错

 

输入flush privileges;命令行执行,再执行 set password for 'root'@'localhost'=password('123456');就可以成功设置密码了

然后退出就可重新输入正确密码进行登陆了。

登陆后可再次执行

 grant all privileges on *.* to root@"%" identified by "123456";

3、navicate链接数据库报错,检查3306端口是否已打开,服务器防火墙是否关闭

systemctl status firewalld.service 查看防火墙状态

systemctl stop firewalld.service 执行停止运行防火墙命令

再次连接成功。

posted @ 2021-06-09 16:21  艾薇-Ivy  阅读(1779)  评论(0编辑  收藏  举报