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
Please check this Why is Hibernate not creating database for MySQL?. Hope it helps.What kind of errors you are getting?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With