简体   繁体   中英

how to create mysql database and tables on the fly by spring boot web app

I think it is possible to create a database and tables by the Spring boot web app. If I have a file with mysql queries to make database, tables, for example, sql_table.sql file. How to use generate databases and table on the fly if no exits?

I can create a new database without any SSL warnings by this:-

spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
spring.jpa.hibernate.ddl-auto=create
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost/aaa?createDatabaseIfNotExist=true&useSSL=true
spring.datasource.username=root
pring.datasource.password=devv
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect

Spring Boot loads SQL scripts from the root of the classpath. You have to specify the data source properties in your application.yml or application.properties file. You must specify your database in data source properties like this:

spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
spring.jpa.hibernate.ddl-auto=create
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=test
spring.datasource.password=

where test is your database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM