What is wrong with my datasource settings to get Spring Boot to connect to MySQL?

13,923

Solution 1

Have you tried connecting to the MySQL server using the CLI?

mysql --host=localhost --port=3360 --user=root --password

I believe you either got the port wrong or the credentials. Default MySQL port is 3306, can it be a typo in the port-number you have specified?

Solution 2

Not connecting to DB means there is failure with the DB connection. Either the credentials are not working or DB service is not reachable to your system. As your URL states that it is in your local system only. So, try connecting with the mysql CLI as already stated above by aksamit.

After providing the correct credentials even the below properties will work fine.

spring.datasource.url = jdbc:mysql://localhost:3360/netgloo_blog
spring.datasource.username = root
spring.datasource.password =

There is no need to specify the driverClassName util you want to use some non-generic driver class. Spring boot will select the driver based on the URL provided and the driver dependancy present in the pom.xml Let us know if you still face issue while connecting to the DB.

Solution 3

Maybe you need to grant access to root from localhost.

If this persists I recommend you to create a new user into your sql and then try to enter with him.

Share:
13,923
guagay_wk
Author by

guagay_wk

Updated on July 22, 2022

Comments

  • guagay_wk
    guagay_wk almost 2 years

    I followed the tutorial below to learn how to write Spring Boot app to access MySQL.

    http://blog.netgloo.com/2014/10/27/using-mysql-in-spring-boot-via-spring-data-jpa-and-hibernate/

    There is an error message with connection to the MySQL database. http://pastebin.com/ykYJacjZ

    I believe something is wrong with the DataSource Settings. Below are my settings;

    spring.datasource.url = jdbc:mysql://localhost:3360/netgloo_blog
    spring.datasource.username = root
    spring.datasource.password = ''
    spring.datasource.driverClassName = com.mysql.jdbc.Driver
    

    I am running a MySQL database using Xampp on port 3360. A database 'netgloo_blog' has been created. I have also created a table users with the fields id, email, name.