由以下原因引起:java.sql.SQLException:用户'root'@'localhost'的访问被拒绝(使用密码:是) [英] Caused by: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

查看:607
本文介绍了由以下原因引起:java.sql.SQLException:用户'root'@'localhost'的访问被拒绝(使用密码:是)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I get the following error when I try to run the app (see below). Already tried the solutions posted on similar topics.

    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)

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

After reading the solution from other similar topics I've tried the below:

- 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,则可以无问题地登录.

If I go from my CMD and I try C:\mysql-5.6.21-winx64\bin>mysql -u root -p -h localhost I can log in with no probs.

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

Any other suggestions please before I will uninstall Mysql and try to reinstal.

推荐答案

错误java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES),使用提供的凭据登录mysql失败.

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

您可以检查两件事.

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

  1. If the provided password is a valid one.

授予特权.

应该像,

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

 FLUSH PRIVILEGES;

如果您没有执行刷新特权,则很可能会遇到相同的错误.

If you didn't execute flush privileges you are likely to get the same error.

例如:

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

这篇关于由以下原因引起:java.sql.SQLException:用户'root'@'localhost'的访问被拒绝(使用密码:是)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆