Spring boot - MySQL settings are not working

前端 未结 4 976
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-19 00:59

I am trying to develop an application using Spring boot and MySQL. As the documentation said, First I created the project using Spring initializr using Intelij Idea, configu

相关标签:
4条回答
  • 2021-01-19 01:23

    As the Spring boot documentation mentioned, what have fixed my issue was adding spring.datasource.platform to the application.properties. That is what I have been missing to initialize the schema using schema-{platform}.sql and data-{platform}.sql.

    {platform} = value of spring.datasource.platform

    So my final application.properties file is,

    spring.datasource.url = jdbc:mysql://localhost:3306/testdb?useSSL=false
    spring.datasource.username = root
    spring.datasource.password = password
    
    spring.datasource.testWhileIdle = true
    spring.datasource.validationQuery = SELECT 1
    
    spring.datasource.driverClassName = com.mysql.jdbc.Driver
    spring.jpa.hibernate.ddl-auto = validate
    spring.jpa.show-sql = true
    spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
    spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
    
    spring.datasource.platform=mysql
    spring.datasource.schema=schema-mysql.sql
    spring.datasource.data=data-mysql.sql
    spring.datasource.initialize=true
    spring.datasource.continue-on-error=true
    
    0 讨论(0)
  • 2021-01-19 01:23

    I faced the same issue and resolved it applying the below code in spring boot 2.0

    spring.datasource.initialization-mode=always

    0 讨论(0)
  • 2021-01-19 01:36

    You need to add below code in application.properties and open your xammp/wamp or server then create yourdatabase for example studentdb same name give in application.properties file

    spring.datasource.url=jdbc:mysql://localhost:3306/yourdatabase
    spring.datasource.username=root
    spring.datasource.password=   
    spring.datasource.driver-class-name=com.mysql.jdbc.Driver
    spring.jpa.database-platform = org.hibernate.dialect.MySQL5Dialect
    spring.jpa.generate-ddl=true
    spring.jpa.hibernate.ddl-auto = update
    
    0 讨论(0)
  • 2021-01-19 01:40

    Please use the key field given below---->

    spring.jpa.hibernate.ddl-auto=create 
    

    or

    spring.jpa.hibernate.ddl-auto=update
    
    0 讨论(0)
提交回复
热议问题