gpt4 book ai didi

java - 由 : java. sql.SQLException: Access denied for user 'root' @'localhost' (using password: YES) 引起

转载 作者:行者123 更新时间:2023-11-29 01:56:24 25 4
gpt4 key购买 nike

当我尝试运行该应用程序时出现以下错误(见下文)。已经尝试过发布在类似主题上的解决方案。

    Exception in thread "main" org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user 'root'@'localhost' (using password: YES))
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:382)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:456)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:464)
at com.caveofprogramming.spring.test.OffersDAO.getOffers(OffersDAO.java:26)
at com.caveofprogramming.spring.test.App.main(App.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user 'root'@'localhost' (using password: YES))
at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
... 10 more
Caused by: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

在阅读了其他类似主题的解决方案后,我尝试了以下方法:

- GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'root' WITH GRANT OPTION;
- Change jdbc:mysql://localhost:3306/mydb to jdbc:mysql://127.0.0.1:3306/mydb
- Create a new User

如果我从我的 CMD 进入并尝试 C:\mysql-5.6.21-winx64\bin>mysql -u root -p -h localhost 我可以毫无问题地登录。

在我卸载 Mysql 并尝试重新安装之前,请提出任何其他建议。

最佳答案

错误 java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES) , mysql login failed using the provided credentials.

您可以检查两件事。

  1. 如果提供的密码有效。

  2. 授予权限。

应该是,

'GRANT ALL PRIVILEGES ON *.* TO '[user name]'@'[server machine name]' IDENTIFIED BY '[password]' WITH GRANT OPTION;'

FLUSH PRIVILEGES;

如果您没有执行刷新权限,您可能会遇到同样的错误。

例如:

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'your_mysql_password' WITH GRANT OPTION;
FLUSH PRIVILEGES;

关于java - 由 : java. sql.SQLException: Access denied for user 'root' @'localhost' (using password: YES) 引起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27722704/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com