今天测试了使用mariadb的使用,我使用的springboot + mariadb 来操作数据库,和以前的代码基本一样,就数据变成了mariadb ,驱动还是使用mysql的。
pom 文件如下
4.0.0 org.springframework.boot spring-boot-starter-parent 2.2.2.RELEASE com.handan deda 0.0.1-SNAPSHOT deda Demo project for Spring Boot 1.8 org.springframework.boot spring-boot-starter-web mysql mysql-connector-java runtime org.projectlombok lombok true org.springframework.boot spring-boot-starter-web org.mybatis.spring.boot mybatis-spring-boot-starter 2.1.1 org.springframework.boot spring-boot-starter-jdbc com.alibaba fastjson 1.2.62 org.projectlombok lombok org.mybatis mybatis-typehandlers-jsr310 1.0.1 org.slf4j slf4j-api 1.7.25 ch.qos.logback logback-core 1.1.11 ch.qos.logback logback-classic 1.1.11 org.apache.httpcomponents httpclient 4.5.6 org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-maven-plugin org.projectlombok lombok
mapper 层的代码如下
@Repository public interface StuMapper { @Insert("insert into stu(sid,name,number,age) values(#{sid},#{name},#{number},#{age})") public void add(Stu stu); }
配置文件如下
server: port: 8050 tomcat: max-http-header-size: 8192 uri-encoding: utf-8 #测试环境 spring: datasource: url: jdbc:mysql://localhost:3306/test?characterEncoding=utf-8&serverTimezone=CTT&useSSL=false&useUnicode=true&autoReconnect=true username: root password: root driver-class-name: com.mysql.cj.jdbc.Driver mybatis: type-aliases-package: com.handan.deda.entity mapper-locations: classpath:mappers/*.xml swagger: enable: true
最后是可以成功添加数据,估计是两个的驱动是可以互换的
开启远程连接代码入下:
grant all privileges on *.* to 'root'@'%'identified by 'root';
刷新配置: flush privileges;