java - MYSQL 模式不断被删除

标签 java mysql hibernate spring-boot database-schema

我有一个在 Ubuntu 服务器上使用 docker 运行的 spring-boot 应用程序,MYSQL DB 在服务器本身上运行,而不是在 docker 镜像中运行。我用于 spring-boot 应用程序的模式不断被随机删除,我总是必须使用备份转储来恢复它。我无法确定这个奇怪问题背后的原因。我试着用谷歌搜索这个问题,但我找不到任何关于这个问题的信息。

什么可能导致数据库被删除?!?

每周随机一次!可能不止于此。我什至无法追踪。

我的 application.yml 有这个:

spring:
  datasource:
    url:  jdbc:mysql://localhost/schemaname?useSSL=false
    username: username
    password: password
    tomcat:
      validation-query: SELECT 1
      test-on-borrow: true

  jpa:
    show-sql: true
    hibernate:
      ddl-auto: update
    properties:
      hibernate:
        dialect: org.hibernate.dialect.MySQL5Dialect

最佳答案

您不应将 ddl-auto 用于生产应用。

引自 Java Persistence with Hibernate .

WARNING: We've seen Hibernate users trying to use SchemaUpdate to update the schema of a production database automatically. This can quickly end in disaster and won't be allowed by your DBA.

此选项仅用于开发。

如果您不想手动运行 SQL 迁移,您应该考虑使用 flyway 或 liquibase 等工具。

关于java - MYSQL 模式不断被删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46674274/

相关文章:

php - sql LIKE 有问题

java - 使用 JPA Hibernate 而不使用 Spring 的多个数据库

java - eclipse 米洛 : How to call method which takes a customDataType as argument?

java - 斯卡拉/Mockito : How to mock the result of a method called inside another method?

java - "Non-static variable this cannot be referenced from a static context"创建对象时

java - 在java客户端中从http响应中提取字符串

mysqlpump 生成不正确的创建 View 查询

数据库设计: Complex Voting System

java - 有人可以解释一下这个 hibernate 方法的作用吗?

mysql - NoSQL 或 Ehcache 缓存?