Home > database >  springboot,Can't connect to my database java.sql.SQLException: Access denied for user 'roo
springboot,Can't connect to my database java.sql.SQLException: Access denied for user 'roo

Time:12-02

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.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:828)
    at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:448)


Process finished with exit code -1

my test

@SpringBootTest
class Springboot04DataApplicationTests {

    @Autowired
    DataSource dataSource;
    @Test
    void contextLoads() throws SQLException {
        System.out.println(dataSource.getClass());

        Connection connection = dataSource.getConnection();
        System.out.println(connection);

    }

}

here is my application.yml

spring:
  datasource:
    username: root
    password: 011575
    url: jdbc:mysql://localhost:3306/mybatis?useSSL=false&useUnicode=true&characterEncoding=UTF-8&allowPublicKeyRetrieval=true
    driver-class-name: com.mysql.cj.jdbc.Driver

I confirmed that my username is root and my pwd is 011575.And also open the mysql service, please help me!!

CodePudding user response:

When springboot reads the data in yml, it will read the pure digital data starting with the number 0 in binary, octal or decimal, and the read value will be different from the original stored value.

so just change your application.yml like this:

password: "011575"

CodePudding user response:

The username and password should be like this

username: root
password: "011575"
  • Related