当前位置: 代码网 > it编程>数据库>Mysql > MySQL遇到“ Access denied for user ”问题的解决办法

MySQL遇到“ Access denied for user ”问题的解决办法

2024年12月03日 Mysql 我要评论
1.检查 mysql 认证方法在 mysql 5.7 及以上版本中,root用户默认可能使用auth_socket插件而不是密码进行认证。要查看认证方法,可以通过以下命令登录 mysql:sudo m

1. 检查 mysql 认证方法

  • 在 mysql 5.7 及以上版本中,root 用户默认可能使用 auth_socket 插件而不是密码进行认证。
  • 要查看认证方法,可以通过以下命令登录 mysql:
sudo mysql -uroot -p 

然后运行以下查询来查看 root 用户的认证方式:

select user, host, plugin from mysql.user where user='root';

如果你看到 auth_socket 插件与 root 用户关联,说明 root 用户使用的是 socket 认证方式。

可以修改认证方式和密码解决,注意,修改了认证方式后密码也要修改

alter user 'root'@'localhost' identified with mysql_native_password by 'new_password';

2. 重置密码(如果使用密码认证)

  • 如果认证方式是基于密码的,可以通过以下步骤重置 root 用户的密码:
  • 停止 mysql 服务:
sudo systemctl stop mysql
  • 使用跳过授权表模式启动 mysql(不进行权限检查):
sudo mysqld_safe --skip-grant-tables &
  • 登录到 mysql:
mysql -u root
  • 更新 root 用户的密码:
use mysql;
update user set authentication_string=password('new_password') where user='root';
flush privileges;
  • 重新启动 mysql 服务:
sudo systemctl start mysql
  • 尝试使用新密码登录:
mysql -u root -p

3. 检查用户权限

  • 如果 root 用户的权限被限制,可以使用以下命令检查用户权限并进行适当调整:
show grants for 'root'@'localhost';

如果需要,可以调整权限,例如:

grant all privileges on *.* to 'root'@'localhost' with grant option;
flush privileges;

按照上述步骤检查和修复后,应该能够解决 access denied 错误。

以上就是mysql遇到“ access denied for user ”问题的解决办法的详细内容,更多关于mysql access denied for user的资料请关注代码网其它相关文章!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com