当我尝试运行应用程序时出现以下错误(请参阅下文)。已经尝试过在类似主题上发布的解决方案。
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
我可以不使用probs登录。
在我卸载Mysql并尝试重新安装之前,请先提出其他建议。
答案 0 :(得分:3)
错误java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
,mysql登录失败,使用提供的凭据。
你可以检查两件事。
如果提供的密码是有效密码。
授予权限。
应该是,
'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;