2

In docker a created network

docker network create mysql-network

Then I create mysql image

docker container run -d -p 3306:3306 --net=mysql-network --name mysql-hibernate -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=test -v hibernate:/var/lib/mysql mysql

When I run docker ps everything seems OK enter image description here

This is my application.properties

spring.jpa.hibernate.ddl-auto=create
useSSL=false
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=password
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL57Dialect

I also tried

spring.datasource.url=jdbc:mysql://mysql-hibernate:3306/test

But I will always get an error on startup

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'test'

How's that possible that it doesn't know database 'test' ? I specified name in docker like this
-e MYSQL_DATABASE=test
What am I missing ?

3
  • 1
    that comes because you didn't create the database 'test' try to create it with command line or use MySQL workbench Commented Sep 16, 2018 at 22:41
  • 1
    well I though the whole point of running docker container in my PC is that I don't have to install mysql / workbench into my computer and configure it :/. I though I can pull an image and use it anyway thanks for pointing me right direction Commented Sep 16, 2018 at 22:54
  • you can also use docker-compose to use tow images as a DB server and an Admin UI (PHPMYADMIN, Adminer ..) search the Hub you can find some images Commented Sep 16, 2018 at 23:00

1 Answer 1

6

I know it is bit late but I'll answer anyway so people coming here can benefit ;) Your configuration overall seems alright. When you get error like this you can add flag param set to true in your application.properties in line where you set datasource url. So you will come up with something like this:

spring.datasource.url=jdbc:mysql://localhost:3306/test?createDatabaseIfNotExist=true

Hope this helps!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.