背景
最新公司一个项目准备将数据库依赖从mysql更换成嵌入式数据库,调研了sqlite、h2等数据库之后,最终选择了MariaDB
为什么选择MariaDB
mariadb与mysql都属于同一类数据库管理系统。但是mariadb与mysql在使用范围和使用目的上都有所不同,两者的主要功能都是为了通过开源社区在维护中,从而获得GPL授权许可。从关系上来看,mariadb是属于数据库管理系统的开发和升级版本,它仅仅代表MySQL的一个分支。
替换过程
pom 依赖新增
<!-- mariaDB4j 驱动 -->
<dependency>
<groupId>ch.vorburger.mariaDB4j</groupId>
<artifactId>mariaDB4j-springboot</artifactId>
<version>2.5.3</version>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>2.7.5</version>
</dependency>
DruidConfig配置新增
/**
* mariaDb 嵌入式数据库 初始化
* @param db MariaDB4jSpringService 中的getDB()
* @param dbName 数据库名称
* @param username 用户名
* @param password 密码
*/
private void mariaDbInit(DB db, String dbName, String username, String password) {
try {
db.createDB(dbName,username,password);
db.source(AdapterConstant.SQL_SCRIPT_PATH,username,password,dbName);
} catch (ManagedProcessException e) {
log.error("mariaDb 嵌入式数据库 初始化 异常", e);
}
}
下面对上面这个方法进行解释
db.createDB(dbName,username,password)
上面这个方法,是为了创建对应的数据库,如果数据库已经存在了,则会跳过;
db.source(AdapterConstant.SQL_SCRIPT_PATH,username,password,dbName)
当你在初始化的时候,需要初始化数据表,你可以使用上面的方法指定数据sql脚本,比如上面的 AdapterConstant.SQL_SCRIPT_PATH 值,如下:
/**
* sql 脚本地址
*/
String SQL_SCRIPT_PATH = "sql/triton.sql";
脚本中,你需要注意:兼容表已经存在、数据已经存在的情况,比如说建表脚本要写成以下格式:
CREATE TABLE IF NOT EXISTS XXXX
然后把这个配置在DataSource 对象初始化的方法中,进行调用,完整的代码如下:
package com.qxwz.adapter.common.config;
import ch.vorburger.exec.ManagedProcessException;
import ch.vorburger.mariadb4j.DB;
import ch.vorburger.mariadb4j.springframework.MariaDB4jSpringService;
import com.alibaba.druid.pool.DruidDataSource;
import com.qxwz.adapter.common.constant.AdapterConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import javax.sql.DataSource;
import java.util.Collections;
/**
* DruidConfig配置
* @author honglei.wan
*/
@Configuration
@Slf4j
public class DruidConfig implements DruidDefaultConfig {
@Value("jdbc:mysql://${db.host}:${db.port}/${db.database}?characterEncoding=utf8&useSSL=false&zeroDateTimeBehavior=convertToNull&tinyInt1isBit=false")
private String mysqlUrl;
@Value("${db.database}")
private String database;
@Value("${db.account}")
private String username;
@Value("${db.account_secret}")
private String password;
@Value("${db.log.save:true}")
private boolean logSave;
@Primary
@Bean("druidDataSource")
public DataSource druidDataSource(MariaDB4jSpringService mariaDB4j) {
try (DruidDataSource druidDataSource = new DruidDataSource()){
mariaDbInit(mariaDB4j.getDB(),database,username,password);
druidDataSource.setUrl(mysqlUrl);
druidDataSource.setUsername(username);
druidDataSource.setPassword(password);
druidDataSource.setDriverClassName(DRIVER_CLASS_NAME);
druidDataSource.setInitialSize(INITIAL_SIZE);
druidDataSource.setMinIdle(MIN_IDLE);
druidDataSource.setMaxActive(MAX_ACTIVE);
druidDataSource.setMaxWait(MAX_WAIT);
druidDataSource.setTimeBetweenEvictionRunsMillis(TIME_BETWEEN_EVICTION_RUNS_MILLIS);
druidDataSource.setMinEvictableIdleTimeMillis(MIN_EVICTABLE_IDLE_TIME_MILLIS);
druidDataSource.setValidationQuery("select 1 ");
druidDataSource.setTestWhileIdle(TEST_WHILE_IDLE);
druidDataSource.setTestOnBorrow(TEST_ON_BORROW);
druidDataSource.setTestOnReturn(TEST_ON_RETURN);
druidDataSource.setPoolPreparedStatements(POOL_PREPARED_STATEMENTS);
druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(MAX_OPEN_PREPARED_STATEMENTS);
druidDataSource.setConnectionProperties(CONNECTION_PROPERTIES);
druidDataSource.setProxyFilters(Collections.singletonList(new AccessLogSaveFilter(logSave)));
return druidDataSource;
}
}
/**
* mariaDb 嵌入式数据库 初始化
* @param db
* @param dbName
* @param username
* @param password
*/
private void mariaDbInit(DB db, String dbName, String username, String password) {
try {
db.createDB(dbName,username,password);
db.source(AdapterConstant.SQL_SCRIPT_PATH,username,password,dbName);
} catch (ManagedProcessException e) {
log.error("mariaDb 嵌入式数据库 初始化 异常", e);
}
}
}
DruidDefaultConfig 如下:
/**
* @author honglei.wan
* @date 2022/9/20 17:47
* @desc druid 默认配置 调用方可选择使用
*/
public interface DruidDefaultConfig {
/**
* 驱动
*/
String DRIVER_CLASS_NAME = "com.mysql.cj.jdbc.Driver";
/**
* 初始化大小
*/
Integer INITIAL_SIZE = 5;
/**
* 最小
*/
Integer MIN_IDLE = 10;
/**
* 最大
*/
Integer MAX_ACTIVE = 20;
/**
* 配置获取连接等待超时的时间,单位是毫秒
*/
int MAX_WAIT = 60000;
/**
* 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
*/
int TIME_BETWEEN_EVICTION_RUNS_MILLIS = 60000;
/**
* 配置一个连接在池中最小生存的时间,单位是毫秒
*/
int MIN_EVICTABLE_IDLE_TIME_MILLIS = 300000;
/**
*
*/
String VALIDATION_QUERY = "SELECT 1 FROM DUAL";
/**
*
*/
boolean TEST_WHILE_IDLE = true;
/**
*
*/
boolean TEST_ON_BORROW = false;
/**
*
*/
boolean TEST_ON_RETURN = false;
/**
*
*/
boolean POOL_PREPARED_STATEMENTS = true;
/**
*
*/
int MAX_OPEN_PREPARED_STATEMENTS = 20;
/**
* 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
*/
String FILTERS ="stat";
/**
* 通过connectProperties属性来打开mergeSql功能;慢SQL记录
*/
String CONNECTION_PROPERTIES ="druid.stat.mergeSql=true;druid.stat.slowSqlMillis=1000";
}
MariaDB4jSpringService 对象说明
DruidConfig 的配置中的MariaDB4jSpringService 对象是我们在引用了pom的那两个包中的对象,在springboot 初始化的时候,会自动加载。
里面的内容如下
springboot启动的时候,会扫描到这个配置类,这时候有人要问了,我spring扫描路径中有没有指定这个路径,怎么扫描到的呢?
大家可以看下这个包下面的这个文件,里面配置了
所以,springboot启动的时候,可以自动加载MariaDB4jSpringService
分页插件修改
package com.qxwz.adapter.common.config;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.apache.commons.lang3.StringUtils;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* MybatisPlus 配置文件
* @author honglei.wan
*/
@Configuration
@MapperScan("com.qxwz.adapter.dal.mapper")
public class MybatisPlusConfig {
/**
* 最大每页查询记录数
*/
public static final long MAX_PAGE_SIZE = 1000;
/**
* 新的分页插件
* 一缓和二缓遵循mybatis的规则
*/
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
// 分页插件: PaginationInnerInterceptor
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MARIADB);
paginationInnerInterceptor.setMaxLimit(MAX_PAGE_SIZE);
interceptor.addInnerInterceptor(paginationInnerInterceptor);
// 防止全表更新与删除插件: BlockAttackInnerInterceptor
BlockAttackInnerInterceptor blockAttackInnerInterceptor = new BlockAttackInnerInterceptor();
interceptor.addInnerInterceptor(blockAttackInnerInterceptor);
return interceptor;
}
}
application.yml 配置文件修改
mariaDB4j:
port: 3306
baseDir: /Users/honglei.wan/Downloads/mariaDB/base
dataDir: /Users/honglei.wan/Downloads/mariaDB/data
# mariadb 数据库替换
db:
host: localhost
port: ${mariaDB4j.port}
database: mariaDB1
username: xxx
password: xxx
springboot 的 Application 修改
细心的同学,在上面应该已经发现了mariaDB的包里面指定了两个自动加载的配置类
还有一个里面是自动加载了一个DataSource,但是我们使用了DruidDataSource,这个对象就不需要加载了,所以Application上要进行调整,如下:
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
至此,这个springboot项目已经从mysql 切换成了 MariaDB,可以正常启动了
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.6.6)
2023-01-10 17:22:40.493<|> INFO<|>42106<|>[]<|>[main]<|>com.qxwz.adapter.AdapterApplication :<|>Starting AdapterApplication using Java 1.8.0_231 on guanliyuans-MacBook-Pro.local with PID 42106 (/Users/honglei.wan/IdeaProjects/triton/target/classes started by honglei.wan in /Users/honglei.wan/IdeaProjects/triton)
2023-01-10 17:22:40.494<|> INFO<|>42106<|>[]<|>[background-preinit]<|>o.h.validator.internal.util.Version :<|>HV000001: Hibernate Validator 6.2.3.Final
2023-01-10 17:22:40.497<|> INFO<|>42106<|>[]<|>[main]<|>com.qxwz.adapter.AdapterApplication :<|>No active profile set, falling back to 1 default profile: "default"
2023-01-10 17:22:41.570<|> INFO<|>42106<|>[]<|>[main]<|>.s.d.r.c.RepositoryConfigurationDelegate :<|>Multiple Spring Data modules found, entering strict repository configuration mode!
2023-01-10 17:22:41.572<|> INFO<|>42106<|>[]<|>[main]<|>.s.d.r.c.RepositoryConfigurationDelegate :<|>Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2023-01-10 17:22:41.638<|> INFO<|>42106<|>[]<|>[main]<|>.s.d.r.c.RepositoryConfigurationDelegate :<|>Finished Spring Data repository scanning in 43 ms. Found 0 Redis repository interfaces.
2023-01-10 17:22:41.835<|> INFO<|>42106<|>[]<|>[main]<|>faultConfiguringBeanFactoryPostProcessor :<|>No bean named 'errorChannel' has been explicitly defined. Therefore, a default PublishSubscribeChannel will be created.
2023-01-10 17:22:41.851<|> INFO<|>42106<|>[]<|>[main]<|>faultConfiguringBeanFactoryPostProcessor :<|>No bean named 'integrationHeaderChannelRegistry' has been explicitly defined. Therefore, a default DefaultHeaderChannelRegistry will be created.
2023-01-10 17:22:42.287<|> INFO<|>42106<|>[]<|>[main]<|>trationDelegate$BeanPostProcessorChecker :<|>Bean 'org.springframework.integration.config.IntegrationManagementConfiguration' of type [org.springframework.integration.config.IntegrationManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2023-01-10 17:22:42.299<|> INFO<|>42106<|>[]<|>[main]<|>trationDelegate$BeanPostProcessorChecker :<|>Bean 'logger.dingtalk-com.qxwz.ad.dingtalk.DingTalkProperties' of type [com.qxwz.ad.dingtalk.DingTalkProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2023-01-10 17:22:42.313<|> INFO<|>42106<|>[]<|>[main]<|>trationDelegate$BeanPostProcessorChecker :<|>Bean 'integrationChannelResolver' of type [org.springframework.integration.support.channel.BeanFactoryChannelResolver] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2023-01-10 17:22:42.598<|> INFO<|>42106<|>[]<|>[main]<|>o.s.b.w.embedded.tomcat.TomcatWebServer :<|>Tomcat initialized with port(s): 8080 (http) 7007 (http)
2023-01-10 17:22:42.610<|> INFO<|>42106<|>[]<|>[main]<|>o.a.coyote.http11.Http11NioProtocol :<|>Initializing ProtocolHandler ["http-nio-8080"]
2023-01-10 17:22:42.611<|> INFO<|>42106<|>[]<|>[main]<|>o.a.coyote.http11.Http11NioProtocol :<|>Initializing ProtocolHandler ["http-nio-7007"]
2023-01-10 17:22:42.622<|> INFO<|>42106<|>[]<|>[main]<|>o.apache.catalina.core.StandardService :<|>Starting service [Tomcat]
2023-01-10 17:22:42.623<|> INFO<|>42106<|>[]<|>[main]<|>org.apache.catalina.core.StandardEngine :<|>Starting Servlet engine: [Apache Tomcat/9.0.60]
2023-01-10 17:22:42.762<|> INFO<|>42106<|>[]<|>[main]<|>o.a.c.c.C.[.[localhost].[/triton] :<|>Initializing Spring embedded WebApplicationContext
2023-01-10 17:22:42.762<|> INFO<|>42106<|>[]<|>[main]<|>w.s.c.ServletWebServerApplicationContext :<|>Root WebApplicationContext: initialization completed in 2229 ms
2023-01-10 17:22:42.917<|> INFO<|>42106<|>[]<|>[main]<|>ch.vorburger.mariadb4j.Util :<|>chmod +x requested on non-existing file: /Users/honglei.wan/Downloads/mariaDB/base/scripts/mysql_install_db
2023-01-10 17:22:42.918<|> INFO<|>42106<|>[]<|>[main]<|>ch.vorburger.mariadb4j.DB :<|>Installing a new embedded database to: /Users/honglei.wan/Downloads/mariaDB/base
2023-01-10 17:22:42.930<|> INFO<|>42106<|>[]<|>[main]<|>ch.vorburger.exec.ManagedProcess :<|>Starting Program [/Users/honglei.wan/Downloads/mariaDB/base/bin/mysql_install_db, --datadir=/Users/honglei.wan/Downloads/mariaDB/data, --basedir=/Users/honglei.wan/Downloads/mariaDB/base, --no-defaults, --force, --skip-name-resolve] (in working directory /Users/honglei.wan/Downloads/mariaDB/base)
2023-01-10 17:22:43.039<|> INFO<|>42106<|>[]<|>[main]<|>ch.vorburger.exec.ManagedProcess :<|>Thread is now going to wait for this process to terminate itself: Program [/Users/honglei.wan/Downloads/mariaDB/base/bin/mysql_install_db, --datadir=/Users/honglei.wan/Downloads/mariaDB/data, --basedir=/Users/honglei.wan/Downloads/mariaDB/base, --no-defaults, --force, --skip-name-resolve] (in working directory /Users/honglei.wan/Downloads/mariaDB/base)
2023-01-10 17:22:43.183<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db: Installing MariaDB/MySQL system tables in '/Users/honglei.wan/Downloads/mariaDB/data' ...
2023-01-10 17:22:44.848<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db: OK
2023-01-10 17:22:44.848<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db:
2023-01-10 17:22:44.848<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db: To start mysqld at boot time you have to copy
2023-01-10 17:22:44.848<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db: support-files/mysql.server to the right place for your system
2023-01-10 17:22:44.848<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db:
2023-01-10 17:22:44.848<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db: PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
2023-01-10 17:22:44.848<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db: To do so, start the server, then issue the following commands:
2023-01-10 17:22:44.848<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db:
2023-01-10 17:22:44.848<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db: '/Users/honglei.wan/Downloads/mariaDB/base/bin/mysqladmin' -u root password 'new-password'
2023-01-10 17:22:44.848<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db: '/Users/honglei.wan/Downloads/mariaDB/base/bin/mysqladmin' -u root -h password 'new-password'
2023-01-10 17:22:44.848<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db:
2023-01-10 17:22:44.848<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db: Alternatively you can run:
2023-01-10 17:22:44.848<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db: '/Users/honglei.wan/Downloads/mariaDB/base/bin/mysql_secure_installation'
2023-01-10 17:22:44.848<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db:
2023-01-10 17:22:44.848<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db: which will also give you the option of removing the test
2023-01-10 17:22:44.848<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db: databases and anonymous user created by default. This is
2023-01-10 17:22:44.849<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db: strongly recommended for production servers.
2023-01-10 17:22:44.849<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db:
2023-01-10 17:22:44.849<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db: See the MariaDB Knowledgebase at http://mariadb.com/kb or the
2023-01-10 17:22:44.849<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db: MySQL manual for more instructions.
2023-01-10 17:22:44.849<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db:
2023-01-10 17:22:44.849<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db: You can start the MariaDB daemon with:
2023-01-10 17:22:44.849<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db: cd '/Users/honglei.wan/Downloads/mariaDB/base' ; /Users/honglei.wan/Downloads/mariaDB/base/bin/mysqld_safe --datadir='/Users/honglei.wan/Downloads/mariaDB/data'
2023-01-10 17:22:44.850<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db:
2023-01-10 17:22:44.850<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db: You can test the MariaDB daemon with mysql-test-run.pl
2023-01-10 17:22:44.850<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db: cd '/Users/honglei.wan/Downloads/mariaDB/base/mysql-test' ; perl mysql-test-run.pl
2023-01-10 17:22:44.850<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db:
2023-01-10 17:22:44.850<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db: Please report any problems at http://mariadb.org/jira
2023-01-10 17:22:44.850<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db:
2023-01-10 17:22:44.850<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db: The latest information about MariaDB is available at http://mariadb.org/.
2023-01-10 17:22:44.850<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db: You can find additional information about the MySQL part at:
2023-01-10 17:22:44.850<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db: http://dev.mysql.com
2023-01-10 17:22:44.850<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db: Consider joining MariaDB's strong and vibrant community:
2023-01-10 17:22:44.850<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db: https://mariadb.org/get-involved/
2023-01-10 17:22:44.850<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysql_install_db:
2023-01-10 17:22:44.851<|> INFO<|>42106<|>[]<|>[Exec Default Executor]<|>c.v.exec.LoggingExecuteResultHandler :<|>Program [/Users/honglei.wan/Downloads/mariaDB/base/bin/mysql_install_db, --datadir=/Users/honglei.wan/Downloads/mariaDB/data, --basedir=/Users/honglei.wan/Downloads/mariaDB/base, --no-defaults, --force, --skip-name-resolve] (in working directory /Users/honglei.wan/Downloads/mariaDB/base) just exited, with value 0
2023-01-10 17:22:44.891<|> INFO<|>42106<|>[]<|>[main]<|>ch.vorburger.mariadb4j.DB :<|>Installation complete.
2023-01-10 17:22:44.891<|> INFO<|>42106<|>[]<|>[main]<|>ch.vorburger.mariadb4j.DB :<|>Starting up the database...
2023-01-10 17:22:44.893<|> INFO<|>42106<|>[]<|>[main]<|>ch.vorburger.mariadb4j.DB :<|>mysqld executable: /Users/honglei.wan/Downloads/mariaDB/base/bin/mysqld
2023-01-10 17:22:44.894<|> INFO<|>42106<|>[]<|>[main]<|>ch.vorburger.exec.ManagedProcess :<|>Starting Program [/Users/honglei.wan/Downloads/mariaDB/base/bin/mysqld, --no-defaults, --console, --skip-grant-tables, --max_allowed_packet=64M, --basedir=/Users/honglei.wan/Downloads/mariaDB/base, --datadir=/Users/honglei.wan/Downloads/mariaDB/data, --port=3306, --socket=/private/var/folders/f6/nn3cdjyd7pxfmd4dj80tkcx40000gq/T/MariaDB4j.3306.sock] (in working directory /Users/honglei.wan/Downloads/mariaDB/base)
2023-01-10 17:22:44.894<|> INFO<|>42106<|>[]<|>[main]<|>ch.vorburger.exec.ManagedProcess :<|>Thread will wait for "mysqld: ready for connections." to appear in Console output of process Program [/Users/honglei.wan/Downloads/mariaDB/base/bin/mysqld, --no-defaults, --console, --skip-grant-tables, --max_allowed_packet=64M, --basedir=/Users/honglei.wan/Downloads/mariaDB/base, --datadir=/Users/honglei.wan/Downloads/mariaDB/data, --port=3306, --socket=/private/var/folders/f6/nn3cdjyd7pxfmd4dj80tkcx40000gq/T/MariaDB4j.3306.sock] (in working directory /Users/honglei.wan/Downloads/mariaDB/base) for max. 30000ms
2023-01-10 17:22:45.090<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysqld: 2023-01-10 17:22:45 140704290555072 [Note] /Users/honglei.wan/Downloads/mariaDB/base/bin/mysqld (mysqld 10.2.11-MariaDB) starting as process 42144 ...
2023-01-10 17:22:45.093<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysqld: 2023-01-10 17:22:45 140704290555072 [Warning] Setting lower_case_table_names=2 because file system for /Users/honglei.wan/Downloads/mariaDB/data/ is case insensitive
2023-01-10 17:22:45.105<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysqld: 2023-01-10 17:22:45 140704290555072 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2023-01-10 17:22:45.105<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysqld: 2023-01-10 17:22:45 140704290555072 [Note] InnoDB: Uses event mutexes
2023-01-10 17:22:45.106<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysqld: 2023-01-10 17:22:45 140704290555072 [Note] InnoDB: Compressed tables use zlib 1.2.8
2023-01-10 17:22:45.106<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysqld: 2023-01-10 17:22:45 140704290555072 [Note] InnoDB: Number of pools: 1
2023-01-10 17:22:45.106<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysqld: 2023-01-10 17:22:45 140704290555072 [Note] InnoDB: Using SSE2 crc32 instructions
2023-01-10 17:22:45.107<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysqld: 2023-01-10 17:22:45 140704290555072 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2023-01-10 17:22:45.113<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysqld: 2023-01-10 17:22:45 140704290555072 [Note] InnoDB: Completed initialization of buffer pool
2023-01-10 17:22:45.117<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysqld: 2023-01-10 17:22:45 140704290555072 [Note] InnoDB: Highest supported file format is Barracuda.
2023-01-10 17:22:45.125<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysqld: 2023-01-10 17:22:45 140704290555072 [Note] InnoDB: 128 out of 128 rollback segments are active.
2023-01-10 17:22:45.125<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysqld: 2023-01-10 17:22:45 140704290555072 [Note] InnoDB: Creating shared tablespace for temporary tables
2023-01-10 17:22:45.125<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysqld: 2023-01-10 17:22:45 140704290555072 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2023-01-10 17:22:45.138<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysqld: 2023-01-10 17:22:45 140704290555072 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2023-01-10 17:22:45.140<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysqld: 2023-01-10 17:22:45 140704290555072 [Note] InnoDB: Waiting for purge to start
2023-01-10 17:22:45.191<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysqld: 2023-01-10 17:22:45 140704290555072 [Note] InnoDB: 5.7.20 started; log sequence number 1670130
2023-01-10 17:22:45.191<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysqld: 2023-01-10 17:22:45 123145513197568 [Note] InnoDB: Loading buffer pool(s) from /Users/honglei.wan/Downloads/mariaDB/data/ib_buffer_pool
2023-01-10 17:22:45.193<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysqld: 2023-01-10 17:22:45 123145513197568 [Note] InnoDB: Buffer pool(s) load completed at 230110 17:22:45
2023-01-10 17:22:45.203<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysqld: 2023-01-10 17:22:45 140704290555072 [Note] Plugin 'FEEDBACK' is disabled.
2023-01-10 17:22:45.261<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysqld: 2023-01-10 17:22:45 140704290555072 [Note] Server socket created on IP: '::'.
2023-01-10 17:22:45.288<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysqld: 2023-01-10 17:22:45 140704290555072 [Note] Reading of all Master_info entries succeded
2023-01-10 17:22:45.288<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysqld: 2023-01-10 17:22:45 140704290555072 [Note] Added new Master_info '' to hash table
2023-01-10 17:22:45.289<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysqld: 2023-01-10 17:22:45 140704290555072 [Note] /Users/honglei.wan/Downloads/mariaDB/base/bin/mysqld: ready for connections.
2023-01-10 17:22:45.289<|> INFO<|>42106<|>[]<|>[Exec Stream Pumper]<|>ch.vorburger.exec.ManagedProcess :<|>mysqld: Version: '10.2.11-MariaDB' socket: '/private/var/folders/f6/nn3cdjyd7pxfmd4dj80tkcx40000gq/T/MariaDB4j.3306.sock' port: 3306 Homebrew
2023-01-10 17:22:45.308<|> INFO<|>42106<|>[]<|>[main]<|>ch.vorburger.mariadb4j.DB :<|>Database startup complete.
2023-01-10 17:22:45.344<|> INFO<|>42106<|>[]<|>[main]<|>ch.vorburger.mariadb4j.DB :<|>Running a command: create database if not exists `triton`;
2023-01-10 17:22:45.344<|> INFO<|>42106<|>[]<|>[main]<|>ch.vorburger.exec.ManagedProcess :<|>Starting Program [/Users/honglei.wan/Downloads/mariaDB/base/bin/mysql, -uhy_ops_user, -phy_ops_user@123, --socket=/private/var/folders/f6/nn3cdjyd7pxfmd4dj80tkcx40000gq/T/MariaDB4j.3306.sock] (in working directory /Users/honglei.wan/Downloads/mariaDB/base)
2023-01-10 17:22:45.445<|> INFO<|>42106<|>[]<|>[main]<|>ch.vorburger.exec.ManagedProcess :<|>Thread is now going to wait for this process to terminate itself: Program [/Users/honglei.wan/Downloads/mariaDB/base/bin/mysql, -uhy_ops_user, -phy_ops_user@123, --socket=/private/var/folders/f6/nn3cdjyd7pxfmd4dj80tkcx40000gq/T/MariaDB4j.3306.sock] (in working directory /Users/honglei.wan/Downloads/mariaDB/base)
2023-01-10 17:22:45.472<|> INFO<|>42106<|>[]<|>[Exec Default Executor]<|>c.v.exec.LoggingExecuteResultHandler :<|>Program [/Users/honglei.wan/Downloads/mariaDB/base/bin/mysql, -uhy_ops_user, -phy_ops_user@123, --socket=/private/var/folders/f6/nn3cdjyd7pxfmd4dj80tkcx40000gq/T/MariaDB4j.3306.sock] (in working directory /Users/honglei.wan/Downloads/mariaDB/base) just exited, with value 0
2023-01-10 17:22:45.496<|> INFO<|>42106<|>[]<|>[main]<|>ch.vorburger.mariadb4j.DB :<|>Successfully ran the command: create database if not exists `triton`;
2023-01-10 17:22:45.497<|> INFO<|>42106<|>[]<|>[main]<|>ch.vorburger.mariadb4j.DB :<|>Running a script file sourced from the classpath at: sql/triton.sql
2023-01-10 17:22:45.497<|> INFO<|>42106<|>[]<|>[main]<|>ch.vorburger.exec.ManagedProcess :<|>Starting Program [/Users/honglei.wan/Downloads/mariaDB/base/bin/mysql, -uhy_ops_user, -phy_ops_user@123, -Dtriton, --socket=/private/var/folders/f6/nn3cdjyd7pxfmd4dj80tkcx40000gq/T/MariaDB4j.3306.sock] (in working directory /Users/honglei.wan/Downloads/mariaDB/base)
2023-01-10 17:22:45.598<|> INFO<|>42106<|>[]<|>[main]<|>ch.vorburger.exec.ManagedProcess :<|>Thread is now going to wait for this process to terminate itself: Program [/Users/honglei.wan/Downloads/mariaDB/base/bin/mysql, -uhy_ops_user, -phy_ops_user@123, -Dtriton, --socket=/private/var/folders/f6/nn3cdjyd7pxfmd4dj80tkcx40000gq/T/MariaDB4j.3306.sock] (in working directory /Users/honglei.wan/Downloads/mariaDB/base)
2023-01-10 17:22:45.601<|> INFO<|>42106<|>[]<|>[Exec Default Executor]<|>c.v.exec.LoggingExecuteResultHandler :<|>Program [/Users/honglei.wan/Downloads/mariaDB/base/bin/mysql, -uhy_ops_user, -phy_ops_user@123, -Dtriton, --socket=/private/var/folders/f6/nn3cdjyd7pxfmd4dj80tkcx40000gq/T/MariaDB4j.3306.sock] (in working directory /Users/honglei.wan/Downloads/mariaDB/base) just exited, with value 0
2023-01-10 17:22:45.653<|> INFO<|>42106<|>[]<|>[main]<|>ch.vorburger.mariadb4j.DB :<|>Successfully ran the script file sourced from the classpath at: sql/triton.sql
2023-01-10 17:22:45.664<|> INFO<|>42106<|>[]<|>[main]<|>com.alibaba.druid.pool.DruidDataSource :<|>{dataSource-0} closing ...
_ _ |_ _ _|_. ___ _ | _
| | |\/|_)(_| | |_\ |_)||_|_\
/ |
3.5.2
2023-01-10 17:22:46.470<|> INFO<|>42106<|>[]<|>[main]<|>c.q.a.common.config.AccessLogSaveFilter :<|>===============AccessLogSaveFilter init===============
2023-01-10 17:22:46.756<|> INFO<|>42106<|>[]<|>[main]<|>com.alibaba.druid.pool.DruidDataSource :<|>{dataSource-1} inited
2023-01-10 17:22:46.761<|>DEBUG<|>42106<|>[]<|>[main]<|>c.q.a.d.m.P.selectList :<|>==> Preparing: SELECT id,param_id,protocol_name,protocol_type,protocol_belong,access_type,trigger_scheduling,retry_count,`status`,gmt_create,gmt_modified FROM protocol_config WHERE (protocol_belong = ? AND `status` = ?)
2023-01-10 17:22:46.787<|>DEBUG<|>42106<|>[]<|>[main]<|>c.q.a.d.m.P.selectList :<|>==> Parameters: access(String), enable(String)
2023-01-10 17:22:46.808<|>DEBUG<|>42106<|>[]<|>[main]<|>c.q.a.d.m.P.selectList :<|><== Total: 0
2023-01-10 17:22:48.570<|> WARN<|>42106<|>[]<|>[main]<|>o.s.b.a.f.FreeMarkerAutoConfiguration :<|>Cannot find template location(s): [classpath:/templates/] (please add some templates, check your FreeMarker configuration, or set spring.freemarker.checkTemplateLocation=false)
2023-01-10 17:22:48.984<|> INFO<|>42106<|>[]<|>[main]<|>o.s.i.endpoint.EventDrivenConsumer :<|>Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2023-01-10 17:22:48.984<|> INFO<|>42106<|>[]<|>[main]<|>o.s.i.channel.PublishSubscribeChannel :<|>Channel 'triton.errorChannel' has 1 subscriber(s).
2023-01-10 17:22:48.985<|> INFO<|>42106<|>[]<|>[main]<|>o.s.i.endpoint.EventDrivenConsumer :<|>started bean '_org.springframework.integration.errorLogger'
2023-01-10 17:22:48.985<|> INFO<|>42106<|>[]<|>[main]<|>o.a.coyote.http11.Http11NioProtocol :<|>Starting ProtocolHandler ["http-nio-8080"]
2023-01-10 17:22:48.994<|> INFO<|>42106<|>[]<|>[main]<|>o.a.coyote.http11.Http11NioProtocol :<|>Starting ProtocolHandler ["http-nio-7007"]
2023-01-10 17:22:48.997<|> INFO<|>42106<|>[]<|>[main]<|>o.s.b.w.embedded.tomcat.TomcatWebServer :<|>Tomcat started on port(s): 8080 (http) 7007 (http) with context path '/triton'
2023-01-10 17:22:49.044<|> INFO<|>42106<|>[]<|>[main]<|>com.qxwz.adapter.AdapterApplication :<|>Started AdapterApplication in 9.12 seconds (JVM running for 13.892)
后记
可能有人发现了MariaDB 使用的链接url,我这里还是写成了
jdbc:mysql://${db.host}:${db.port}/${db.database}?characterEncoding=utf8&useSSL=false&zeroDateTimeBehavior=convertToNull&tinyInt1isBit=false
没有像网上其他人使用jdbc:mariadb:..... 这种形式,包括驱动也是使用的mysql的驱动没有使用
org.mariadb.jdbc.Driver
那是因为mariadb 是mysql的一个分支,目前为止,mysql兼容mariadb。以后的情况,就不知道了