createDatabaseIfNotExist=true not working in .properties file in maven project
Solution 1
Please check this Why is Hibernate not creating database for MySQL?. Hope it helps.What kind of errors you are getting?
Solution 2
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
Shaun Lavelle
Updated on July 26, 2022Comments
-
Shaun Lavelle almost 2 years
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
-
Shaun Lavelle over 8 yearsI have updated my question with the .properties file. seems pretty much the same.
-
Shaun Lavelle over 8 yearsi get errors like, something to do with memory leak, and something wrong with my sql syntax, Error creating bean with name 'configureDataSource'
-
Vikas Sharma over 8 yearsReplace hibernate.dialect=org.hibernate.dialect.MySQLDialect with hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
-
Shaun Lavelle over 8 yearsi added the 5 to the dialect but still no change
-
Shaun Lavelle over 8 yearsWARNING: The web application [/RaysRentalSystem] appears to have started a thread named [MySQL Statement Cancellation Timer] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
-
Shaun Lavelle over 8 yearsCaused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-database' at line 1
-
Vikas Sharma over 8 yearsremove '-' from rays-database in dataSource.url=jdbc:mysql://localhost/rays-database?createDatabaseIfNotExist=true