java.sql.SQLException: Access denied for user ‘root’@‘localhost’ (using password: YES)错误原因

java.sql.SQLException: Access denied for user ‘root’@‘localhost’ (using password: YES)错误原因 解决方案:

  1. 用户对应的密码不正确
    检查输入的用户名 密码 与数据库用户名 密码 是否一致
    这里密码不正确有几种常见情况:
    (1)连接池多个空格
    (2)mysql5.7后mysql系统表user里密码对应的字段不是password
    是authentication_string字段
    命令行依次输入:
mysql
use mysql;
select * from user where user='你的用户名'\G;

java.sql.SQLException: Access denied for user ‘root’@‘localhost’ (using password: YES)错误原因_第1张图片
authentication_string为5.7后mysql的密码字段
java.sql.SQLException: Access denied for user ‘root’@‘localhost’ (using password: YES)错误原因_第2张图片
password原来的密码字段
然后更新:

update user set authentication_string=password('你的密码') where user='你的用户名';
  1. localhost映射问题
    java.sql.SQLException: Access denied for user ‘root’@‘localhost’ (using password: YES)错误原因_第3张图片
    localhost换成127.0.0.1

3,第三种可能就是MYSQL的权限问题

GRANT
  [权限] 
ON [.] 
TO [用户名]@[IP] 
IDENTIFIED BY [密码] 
# WITH GRANT OPTION;

示例:

GRANT
  ALL PRIVILEGES
ON *.*
TO admin@'175.155.59.133'
IDENTIFIED BY 'admin';

每次更新权限后记得刷新权限
FLUSH PRIVILEGES;

java.sql.SQLException: Access denied for user ‘root’@‘localhost’ (using password: YES)错误原因_第4张图片

权限问题具体参看这篇博文:
https://blog.csdn.net/weixin_42109012/article/details/102684153

4,数据库和驱动不匹配
https://blog.csdn.net/qq_41679818/article/details/105857793

你可能感兴趣的:(mysql,问题或bug,java,java,sql,mysql)