配置application.yml
spring:
application:
name: lys-app
main:
allow-bean-definition-overriding: true
datasource:
name: lys-app
url: jdbc:mysql://ip:3306/test?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8&useSSL=false
username: root
password: 123456
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
druid:
initial-size: 5
min-idle: 5
max-active: 25
max-wait: 1000
time-between-eviction-runs-millis: 60000
validation-query: SELECT 1 as nums
test-while-idle: true
test-on-borrow: false
test-on-return: false
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 20
connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
initialization-mode: always
schema: classpath:/sql/test_schema.sql
data: classpath:/sql/test_pg_data.sql
separator: $$$
continue-on-error: true # 根据实际需求情况设置
test_schema.sql
SET NAMES utf8mb4; $$$
SET FOREIGN_KEY_CHECKS = 0; $$$
SET GLOBAL time_zone = '+8:00'; $$$
CREATE TABLE IF NOT EXISTS `tb_user` (
`user_id` varchar(64) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT 'id',
`name` varchar(64) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '姓名',
PRIMARY KEY (`user_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = Dynamic; $$$
SET FOREIGN_KEY_CHECKS = 1; $$$
test_pg_data.sql
-- delimiter $$$
CREATE PROCEDURE IF NOT EXISTS init_data()
BEGIN
TRUNCATE TABLE `cloud_rds`.`tb_user`;
INSERT INTO `cloud_rds`.`tb_user`(`user_id`, `name`) VALUES ('1', 'liuyunshengsir1');
INSERT INTO `cloud_rds`.`tb_user`(`user_id`, `name`) VALUES ('2', 'liuyunshengsir2');
INSERT INTO `cloud_rds`.`tb_user`(`user_id`, `name`) VALUES ('3', 'liuyunshengsir3');
INSERT INTO `cloud_rds`.`tb_user`(`user_id`, `name`) VALUES ('4', 'liuyunshengsir4');
END $$$
-- delimiter
CALL init_data(); $$$
DROP PROCEDURE init_data; $$$