首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

解决Java应用程序中的SQLException:Access denied for user ‘root‘@‘localhost‘ 错误

java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:127) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:862) at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:444) at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:230) at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:226) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:247) at BookManagement.<init>(BookManagement.java:23) at BookManagement.main(BookManagement.java:66)

02

MySQL 权限操作

MySQL 权限系统保证所有的用户只执行允许做的事情。当连接 MySQL 服务器时,用户的身份由用户从那儿连接的主机和用户指定的用户名来决定。连接后发出请求后,系统根据用户的身份和用户想做什么来授予权限。MySQL 中采用用户名 + 主机名来识别用户的身份。例如,从 abc.com 连接的用户 root 不一定和从 bcd.com 连接的 root 是同一个人。MySQL 通过允许你区分在不同的主机上碰巧有同样名字的用户来处理它,可以对 root 从 abc.com 进行的连接授与一个权限集,而为 root 从 bcd.com 的连接授予一个不同的权限集。MySQL存取控制包含2个阶段:  ♞ 阶段1:服务器检查是否允许你连接。  ♞ 阶段2:假定能连接,服务器检查你发出的每个请求。看你是否有足够的权限实施它。

03

解决MySQL连接问题:Access Denied和SSL警告;MySQL数据库连接失败:Access Denied异常的解决方法;如何在Java应用程序中正确配置MySQL数据库连接

报错“Connected to the target VM, address: '127.0.0.1:59549', transport: 'socket' Wed Sep 13 16:56:02 CST 2023 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. java.sql.SQLException: Access denied for user 'username'@'localhost' (using password: YES) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:127) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:862) at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:444) at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:230) at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:226) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:247) at BookManagement.<init>(BookManagement.java:21) at BookManagement.main(BookManagement.java:62) Disconnected from the target VM, address: '127.0.0.1:59549', transport: 'socket' 进程已结束,退出代码 0

01
领券