Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

createDatabaseIfNotExist=true not working in .properties file in maven project

I have a maven project that connects to a database that already exists. however i wanted to change it so that if the database doesn't already exist. it gets created. so i added in this extra code ?createDatabaseIfNotExist=true to this line.

dataSource.url=jdbc:mysql://localhost/rays-database?createDatabaseIfNotExist=true

And i got a lot of errors, so my question is; is there any extra configuration that im missing in order to use ?createDatabaseIfNotExist=true

I also tried adding the port number which didn't make any difference which i didn't expect it to.

dataSource.url=jdbc:mysql://localhost:3306/rays-database?createDatabaseIfNotExist=true

here is my .properties file:

 dataSource.driverClassName=com.mysql.jdbc.Driver
 dataSource.url=jdbc:mysql://localhost/rays-database?createDatabaseIfNotExist=true
 dataSource.username=root
 dataSource.password=

 hibernate.dialect=org.hibernate.dialect.MySQLDialect
 hibernate.show_sql=true
 hibernate.hbm2ddl.auto=create
like image 603
Shaun Lavelle Avatar asked Oct 08 '15 10:10

Shaun Lavelle


2 Answers

Please check this Why is Hibernate not creating database for MySQL?. Hope it helps.What kind of errors you are getting?

like image 62
Vikas Sharma Avatar answered Oct 17 '22 13:10

Vikas Sharma


You can try this one, you have to add port and delete this(-) on the db name.

spring.datasource.url = jdbc:mysql://127.0.0.1:3306/DbName?createDatabaseIfNotExist=true&autoReconnect=true&useSSL=false&useUnicode=yes&characterEncoding=UTF-8&allowPublicKeyRetrieval=true
like image 30
Salil Das Avatar answered Oct 17 '22 12:10

Salil Das