mysql执行sql脚本文件

发布时间: 2023-11-21 11:32 阅读: 文章来源:1MUMB1790PS
简介

需要注意的是,配置之后,每次启动都会执行一遍sql文件。但一般要求只执行一次。所以在sql语句中,处理好如果已存在的处理方式。如建表语句中加入:if not exist 判断建表。

1、文件目录

2、application-dev.yml#用于开发环境server:port: 8000max-http-header-size: 8192servlet:encoding:charset: UTF-8force: trueenabled: truelogging:level:root: infospring:mvc.async.request-timeout: 20000application:name: druid-jdbc-mysqlsql:init:encoding: utf-8# mode: always - Spring Boot应用启动时始终执行数据库初始化# mode: embedded - 只初始化内存数据库,比如H2数据库# mode: never:- 从不执行初始化数据库mode: always# 数据库平台内容配置项,主要有mysql、postgresql、oracle等platform: mysql# sql脚本的位置#data-locations:#- classpath:data-all.sql# 创建表sql脚本的位置schema-locations:- classpath:schema-all.sqldatasource:url: jdbc:mysql://192.168.31.12:3306/test?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=falseusername: rootpassword: 123123# old: com.mysql.jdbc.Driverdriver-class-name: com.mysql.cj.jdbc.Drivertype: com.alibaba.druid.pool.DruidDataSource# ============================== druid ============================== #druid:#最大活跃数max-active: 20#初始化数量initial-size: 1#最大连接等待超时时间max-wait: 60000min-idle: 1#打开PSCache,并且指定每个连接PSCache的大小poolPreparedStatements: truemax-pool-prepared-statement-per-connection-size: 20# max-open-prepared-statements: 和上面的等价# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒time-between-eviction-runs-millis: 60000min-evictable-idle-time-millis: 300000# max-evictable-idle-time-millis# select ‘x‘validation-query: select 1 from dual# validation-query-timeout:test-while-idle: truetest-on-borrow: falsetest-on-return: false# 配置监控统计拦截的filters,去掉后监控界面sql将无法统计,‘wall‘用于防火墙filters: stat, wall, log4j3、schema-all.sql# 初始化创建数据库表CREATE TABLE IF NOT EXISTS `my_user122` (`id` int(11) NOT NULL AUTO_INCREMENT,`name` varchar(255) COLLATE utf8mb4_bin NOT NULL,PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;4、pom.xml4.0.0org.springframework.bootspring-boot-starter-parent2.7.12UTF-8UTF-81.8druid-jdbc-mysql-encrypt-datasourceorg.find${project-name}0.0.1-SNAPSHOTjar${project-name}${project-name}org.springframework.bootspring-boot-starter-jdbccom.alibabadruid-spring-boot-starter1.2.16log4jlog4j1.2.17com.alibabadruid-spring-boot-starter1.2.16mysqlmysql-connector-java8.0.32org.springframework.bootspring-boot-starter-weborg.apache.httpcomponentshttpclient4.5.14org.jsonjson20180130com.alibabafastjson2.0.32javax.injectjavax.inject1org.springframework.bootspring-boot-starter-validationorg.apache.maven.pluginsmaven-resources-pluginUTF-8org.apache.maven.pluginsmaven-source-pluginattach-sourcesjarmaven-compiler-plugin1.81.8org.apache.maven.pluginsmaven-jar-plugintruelib/org.fiend.MySpringbootAppfalseorg.apache.maven.pluginsmaven-dependency-plugincopy-dependenciespackagecopy-dependencies${project.build.directory}/libfalsefalsetrue

•••展开全文