MySQL登录时报错
提示拒绝访问 Access denied
出现access denied的原因有如下可能:
1)MySQL服务没启动:检查服务器状态
systemctl status mysqld
MySQL服务运行正常,若MySQL已经没有启动,重启MySQL服务器:systemctl restart mysqld
2)用户的端口号或者IP导致:若用户的端口号与IP(3306/3307)不一致,打开my.ini文件进行编辑。全部编辑替换为: port=X
3)root用户的密码错误:解决方案
vim /etc/f文件
在[mysqld]后添加skip-grant-tables(登录时跳过权限检查)
重启MySQL服务:systemctl restart mysqld
重启完成 输入mysql –uroot –p;直接回车
登录过后修改root密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassWord1.';
如果出现:ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
刷新 flush privileges;
再次修改:ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassWord1.';
退出:exit
再把f的skip-grant-tables删除或者注释掉
重启MySQL:systemctl restart mysqld
重新用新密码登录成功