- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
因此,当我尝试从 Java 代码连接到 MySQL 数据库时,出现错误 java.sql.SQLException: Access returned for user ''@'localhost' (using password: NO)
。我能找到的所有内容根本没有解决问题,而且代码非常基本。之前在项目中用过,发现很多教程都是这样的。首先是相关代码:
//Inside class that manages SQLConnection
public SQLTransceiver(String url){
this.connectionURL = url;
this.reconnect();
}
public void reconnect(){
try {
Connection connection = DriverManager.getConnection(this.connectionURL); //Where the error occurs
this.currentConnection = connection;
} catch (SQLException e) {
e.printStackTrace();
}
}
//Inside main class I call this for testing purpose
String s = "jdbc:mysql://localhost:3306/tableName" +
"?user=user" +
"&password=thePassword" +
"&serverTimezone=MET";
DataTransreciever transreciever = new SQLTransceiver(s);
注意:我可以完美地登录 MySQL 工作台中的数据库并执行从创建/更改表到插入等所有操作。
整个 Stacktrace 看起来像这样:
java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:208)
at main.data.SQLTransceiver.reconnect(SQLTransceiver.java:31)
at main.data.SQLTransceiver.<init>(SQLTransceiver.java:20)
at main.ui.toDoPane.ToDoPane.<init>(ToDoPane.java:208)
at main.ui.Window.start(Window.java:40)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)
那么我做了什么来解决这个问题:这让我想知道为什么它没有说明哪个用户被拒绝,注意到它声明“用户''@'localhost'被拒绝。所以我确实输入了错误的密码,并且出现了这个错误:
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:208)
at main.data.SQLTransceiver.reconnect(SQLTransceiver.java:31)
at main.data.SQLTransceiver.<init>(SQLTransceiver.java:26)
at main.Main.main(Main.java:29)
所以看起来它在某个时候确实检查了用户和密码。如果用户和密码正确,它只会给出第一个错误。
因此,我进行了一些查找,并多次得到了针对此问题所述的解决方案(尽管通常它确实指出“使用密码:是”而不是“否”):
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
它指出我应该运行以下语句:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '%password%' WITH GRANT OPTION;
问题是我无法运行它。当我尝试在 MySQL Workbench 中运行它时,出现以下错误:
0 5 01:12:32 GRANT ALL PRIVILEGES ON *.* TO 'user'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IDENTIFIED BY 'password' WITH GRANT OPTION' at line 1 0.000 sec
此外,我尝试完全删除 MySQL 并重新安装它。这没有帮助。
免责声明:出于隐私原因,密码和用户已更改。就错误而言,使用连接字符串和属性类调用 DriverManager 并没有什么区别,我确实尝试过这样做。抱歉,我的英语比较基础,可能还很糟糕。我正在使用带有 InnoDB 引擎的 MySQL Server 8.0.20 Community。 J/Connector 和 MySQL Notifier 适用于同一版本。我使用从 https://dev.mysql.com/downloads/mysql/ 下载的 Windows Installer 安装了所有内容(包括工作台)我使用的是 Windows 10。
当我删除“serverTimezone”参数时,出现以下错误:
java.sql.SQLException: The server time zone value 'Mitteleurop�ische Sommerzeit' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the 'serverTimezone' configuration property) to use a more specifc time zone value if you want to utilize time zone support.
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:76)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:208)
at main.data.SQLTransceiver.reconnect(SQLTransceiver.java:31)
at main.data.SQLTransceiver.<init>(SQLTransceiver.java:26)
at main.Main.main(Main.java:28)
我不知道这是否有帮助,但这是可能的。
提前非常感谢:)
最佳答案
所以至少解决问题的是再次重新安装 MySQL Server。
不同之处在于,这次我确保为每个组件(服务器、Connector/J、Notifier 和 Workbench)选择"new"密码加密(“caching_sha2_password”)。
尽管我不明白这会如何导致这样的错误,或者这是否是它修复的错误。
感谢所有竭尽全力提供帮助的人:D
关于java.sql.SQLException : Access denied for user '' @'localhost' (using password: NO),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62096031/
我在 Controller 中有此功能,但我无法重置密码,因为我想将字符长度更改为 5 位数字。 public function postReset(Request $request) { $th
我正在学习使用 maven password encryption能力,我想知道如何选择参数 .有两件事我不明白: 1) mvn --encrypt-master-password foobar总会给
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 关闭 9 年前。 这个问题似乎不是关于 a specific programming problem,
我想知道其他电子商务/行业网站上“忘记密码”流程的“标准”使用率是多少?目前,没有多少人会访问我网站上的“忘记密码”链接,但这主要是因为大多数人没有密码。我正在安装新的登录名(这将鼓励人们创建密码),
从存储库中提取源代码需要我的密码。 SourceTree 默认记住此密码。我不希望 SourceTree 记住我的密码。我每次都必须禁用此功能! 如何禁用此默认行为?谢谢! 最佳答案 我在 Mac 上
这个问题已经有答案了: When to use single quotes, double quotes, and backticks in MySQL (13 个回答) 已关闭 5 年前。 Erro
我正在为我的 iOS 应用程序使用 Firebase 身份验证服务。我想通过电子邮件或谷歌登录提供商登录应用程序。我申请了firebase instractions . 我可以使用电子邮件和密码登录。
我正在尝试了解角色密码在 Postgres 中的运作方式。 https://www.postgresql.org/docs/current/static/sql-createrole.html表示加密
为什么“确认密码和密码相同”部分不起作用?意思是,使用“getElementById”来处理密码和确认密码的部分。每个部分都有效,但特定部分除外。它不会在文本字段周围显示红色框。谁能帮我吗?
我遇到了 Flutter 的 TextInputType 没有密码类型的问题: /// All possible enum values. static const List values = con
我正在尝试使用 Azure 应用服务创建应用程序。 但是,它显示上述错误:无法识别的参数: 我使用的命令是 --> az ad app create --available-to-other-tena
我正在尝试使用 Azure 应用服务创建应用程序。 但是,它显示上述错误:无法识别的参数: 我使用的命令是 --> az ad app create --available-to-other-tena
我有(数千个)包含各种(数十亿)行的 csv 文件,例如: 组合.csv example0@domain.tld:passw0rd ex.a.m-pl_e1@domain.tld;p@££w0r46&
在我的 Spring 3 MVC 应用程序中,用户需要保存密码,如果他们也能够在保存时确认密码,那将是一个不错的功能。 在 bean 中,我使用基于注释的验证。是否有注释 validator 可用于执
我在 pgsql 中创建了一个没有密码的新用户。但是当我尝试为这个用户创建一个数据库时,它提示输入密码 >createuser -d -S -R -U postgres test1 Password:
我创建了 Form 这种形式的小部件有多个 TextFormFeild 我创建了自定义 BoxFeild .我面临与 相关的问题auto-validation 来自表单小部件。无法验证确认密码中的密码
在 SQL Server 2008 R2 标准版上,每当我尝试通过报表管理器更新数据源凭据时,我都无法保存更改,因为它会报告消息 "The password is not valid. Please
我有一个用 JAVA 编写并部署在 Wildfly 8.2 上的小型 REST 应用程序。当我尝试使用 javax 安全库登录时,出现错误 FailedLoginException: Password
验证错误:子“密码”失败,因为运行测试时显示[“密码”是必需的]错误 我使用 hapijs v17.2.3 和 mongodb 作为后端。我正在尝试使用 lab 和 code 执行单元测试。这是我的t
我使用 visual studio 2010 创建了一个登录表单,其中包含用户名的输入文本和 userpass 的密码类型输入。我有最新的 chrome 版本 59.0.3071.115(官方构建)(
我是一名优秀的程序员,十分优秀!