引起的:java.sql。SQLException:用户“root”@“localhost”(使用密码:YES)拒绝访问

时间:2022-03-04 22:49:39

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

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.

如果我从CMD开始,我尝试C:\mysql-5.6.21-winx64\bin>mysql -u root -p -h localhost,我可以不使用probs登录。

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

在我卸载Mysql并尝试恢复之前,请给出其他建议。

1 个解决方案

#1


3  

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

java.sql的错误。SQLException:用户“root”@“localhost”(使用密码:YES)拒绝访问,mysql登录失败使用提供的凭证。

two things you can check.

你可以检查两件事。

  1. If the provided password is a valid one.

    如果提供的密码是有效的。

  2. Grant privileges.

    授予特权。

It should be like ,

应该是,

'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.

如果您没有执行刷新特权,您可能会得到相同的错误。

eg:

例如:

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

#1


3  

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

java.sql的错误。SQLException:用户“root”@“localhost”(使用密码:YES)拒绝访问,mysql登录失败使用提供的凭证。

two things you can check.

你可以检查两件事。

  1. If the provided password is a valid one.

    如果提供的密码是有效的。

  2. Grant privileges.

    授予特权。

It should be like ,

应该是,

'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.

如果您没有执行刷新特权,您可能会得到相同的错误。

eg:

例如:

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