spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# Spring Boot 2.5.0 init schema & data
# init script 이름
spring.sql.init.username=root
# init script 수행 user password
spring.sql.init.password=
# init script 위치
spring.sql.init.schema-locations=classpath*:schema-all.sqlr
resource 폴더에 schema-all.sql 생성
create table test.user_info
(
id int unsigned auto_increment comment 'user id'
primary key,
open_id varchar(255) default '' null comment 'openid',
nick_name varchar(255) default '' null comment '닉네임',
head_img varchar(255) default '' null comment '프로핀사진',
sex varchar(255) default '' null comment '성별',
phone varchar(255) default '' null comment '핸드폰',
province varchar(255) default '' null comment '지역',
city varchar(255) default '' null comment '도시',
country varchar(255) default '' null comment '구/동',
status tinyint unsigned default 0 not null comment '삭제여부 0:아니 1:예',
create_time datetime not null comment '생성시간',
update_time datetime not null comment '수성시간'
)
comment '사용자 테이블';
설정후 springboot 구동하면Database에 jpa를 통하여 생성 된 기본 테이블 및 데이터가 생성된걸 확인 할수 있다.
spring.sql.init.enabled : 데이터를 초기화 할 것인지 선택 기본 true , false 를 선택하여 disable 상태로 만들어 놓는다. -D 명령어 사용 가능.
spring.sql.init.username和spring.sql.init.password : 스크립트 수행 사용자와 패스워드 . 해당 설정은 중요하다. 보안에서 db 계정마다 권한이 다르므로 해당 설정을 꼭 해줘야 생성, 삭제 명령 등 위험한 명령어 및 스크립트를 수행하는걸 방지한다.
spring.sql.init.schema-locations : schema 변경 관련 sql 스크립트, 다중 설정가능 기본값은 ; 임. spring.sql.init.data-locations : data 관련 스크립트설정, 다중설정가능 , 기본값은 ; 임. spring.sql.init.encoding:스크립트 인코딩
spring.sql.init.separator : 다중 설정 .sql 파일명 구분자 기본 값 ; 임
spring.sql.init.continue-on-error : 스크립트 실행 중 오류발생시 계속 진행할것인지 결정하는 값.기본값은 false.