简体   繁体   中英

Unable to connect my spring boot application to mysql

I have got this access denied exception :

java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO) org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta-data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO) 018-08-23 00:55:21.791 INFO 1260 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default' 2018-08-23 00:55:21.813 INFO 1260 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [ name: default ...] 2018-08-23 00:55:22.180 INFO 1260 --- [ main] org.hibernate.Version
: HHH000412: Hibernate Core {5.2.17.Final} 2018-08-23 00:55:22.181 INFO 1260 --- [ main] org.hibernate.cfg.Environment
: HHH000206: hibernate.properties not found 2018-08-23 00:55:22.221 INFO 1260 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final} 2018-08-23 00:55:22.351 INFO 1260 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting... 2018-08-23 00:55:23.445 ERROR 1260 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.

application properties file:

    spring.thymeleaf.cache=false

    #===============================
    #DATA SOURCE
    #===============================

    #set here configurations for the database connection

    spring.datasource.url=jdbc:mysql://localhost:3306/bookstoredatabase?verifyServerCertificate=false&useSSL=true
    #username and secret
    spring.datasource.data.username=root
    spring.datasource.data.password=

    #keep connection alive if idle for long time
    spring.datasource.testWhileIdle = true
    spring.datasource.validationQuery = SELECT 1


    #===================
    #jpa/hibernate
    #===================
    #use spring.jpa.properties.* for hibernate native properties
    #stripped before adding them to the entity manager

    #show or not log for each sql query
    spring.jpa.show-sql=true

    #jdbc driver class
    spring.datasource.driver-class-name=com.mysql.jdbc.Driver

    #the project
    spring.jpa.hibernate.ddl-auto=create


    #allows hibernate to generat sql optimised for particular dbms
    spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

my java file:

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class BookstoreApplication {

    public static void main(String[] args) {
        SpringApplication.run(BookstoreApplication.class, args);
    }
}

It seems that your database username and password are not set with correct property names, as in spring-boot the name of the properties are predefined and only those should be used while giving configuration information. Just try below property keys for username and password :

spring.datasource.username = 
spring.datasource.password = 

Provide appropriate values..

java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)

It seems your user password is incorrect. Try to login MySQL with same credentials and it will display the same error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM