SpringBoot 启动时数据库初始化
程序员文章站
2022-05-03 16:01:16
...
spring.datasource
默认sql文件位置配置
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
username: root
password: 123456
url: jdbc:mysql://localhost:3306/car? :useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
initialization-mode: always
sql-script-encoding: utf-8
其中:schema.sql:是DDL(数据定义语言),针对表的操作
data.sql:是DML(数据操纵语言),针对数据的操作
自定义sql文件位置配置
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
username: root
password: 123456
url: jdbc:mysql://localhost:3306/car?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
initialization-mode: always
sql-script-encoding: utf-8
schema:
- classpath:new.sql
data:
- classpath:newd.sql
schema:之后指定sql(DDL)的位置和名称
data: 之后指定sql(DML)的位置和名称