Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 627
masiboo Avatar asked Mar 13 '18 17:03

masiboo


People also ask

Can we configure MySQL with spring boot?

Configure MySQL for Spring Boot ApplicationSpring Boot provides a ready-to-use support for H2 Database. Spring Boot automatically set up in memory H2 database if it detects H2 configurations in the classpath.

How do you connect your spring boot application to database?

To access the Relational Database by using JdbcTemplate in Spring Boot application, we need to add the Spring Boot Starter JDBC dependency in our build configuration file. Then, if you @Autowired the JdbcTemplate class, Spring Boot automatically connects the Database and sets the Datasource for the JdbcTemplate object.

What is MySQL driver dependency in spring boot?

The spring-boot-starter-data-jpa is a starter for using Spring Data JPA with Hibernate. The mysql-connector-java dependency is for the MySQL database driver. The spring-boot-maven-plugin provides Spring Boot support in Maven, allowing us to package executable JAR or WAR archives.


1 Answers

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
like image 192
masiboo Avatar answered Nov 12 '22 07:11

masiboo