> For the complete documentation index, see [llms.txt](https://jack80342.gitbook.io/spring-boot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jack80342.gitbook.io/spring-boot/ix.-how-to-guides/80.-database-initialization/80.2-initialize-a-database-using-hibernate.md).

# 80.2 使用Hibernate初始化数据库

你可以显式设置`spring.jpa.hibernate.ddl-auto`。标准的Hibernate属性值有`none`、`validate`、`update`、`create`与`create-drop`。Spring Boot根据你的数据库是否为内嵌数据库来选择相应的默认值。如果是内嵌型的则默认值为`create-drop`，否则为`none`。通过查看`Connection`类型可以检查是否为内嵌型数据库。hsqldb、h2和derby是内嵌的，其他都不是。当从内存数据库迁移到一个真正的数据库时，你需要当心，在新的平台中不能对数据库表和数据是否存在进行臆断，你也需要显式设置`ddl-auto`，或使用其他机制初始化数据库。

**注** 通过启用`org.hibernate.SQL`记录器，你可以输出模式创建。如果你启用了[debug模式](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-logging-console-output)，这些会自动完成。

此外，如果Hibernate从零开始创建模式（`ddl-auto`属性被设置为`create`或者`create-drop`），启动时处于classpath根目录下的`import.sql`文件会被执行。这在demos或测试时很有用，但在生产环境中你可能不期望这样。这是Hibernate的特性，和Spring没有一点关系。
