springboot 配置mysql连接

server.port=8888

spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

 

说明:url是指路径,端口号---库(test)---启用编码---编码为utf-8--是否启用ssl协议--指定时区

  SSL协议提供服务主要:         
       1)认证用户服务器,确保数据发送到正确的服务器;    .
       2)加密数据,防止数据传输途中被窃取使用;
       3)维护数据完整性,验证数据在传输过程中是否丢失;

   当前支持SSL协议两层:
            SSL记录协议(SSL Record Protocol):建立靠传输协议(TCP)高层协议提供数据封装、压缩、加密等基本功能支持
        SSL握手协议(SSL Handshake Protocol):建立SSL记录协议用于实际数据传输始前通讯双进行身份认证、协商加密
        算法、 交换加密密钥等。
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论
好的,下面是配置 MySQL 连接池的步骤: 1. 添加 MySQL 依赖 首先在 pom.xml 中添加 MySQL 依赖,例如: ```xml <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.23</version> </dependency> ``` 2. 配置 application.properties 在 src/main/resources 目录下创建 application.properties 文件,并添加以下配置: ```properties # 数据源配置 spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8 spring.datasource.username=root spring.datasource.password=123456 spring.datasource.driver-class-name=com.mysql.jdbc.Driver # 连接配置 spring.datasource.initial-size=5 spring.datasource.max-active=50 spring.datasource.min-idle=5 spring.datasource.max-idle=10 ``` 其中,spring.datasource.url 是数据库连接地址spring.datasource.username 和 spring.datasource.password 是数据库用户名和密码,spring.datasource.driver-class-name 是数据库驱动的类名。 spring.datasource.initial-size 是连接池初始化大小,spring.datasource.max-active 是连接池最大连接数,spring.datasource.min-idle 是连接池最小空闲连接数,spring.datasource.max-idle 是连接池最大空闲连接数。 以上是基本的配置,你可以根据自己的情况进行调整。 3. 测试连接池 在代码中使用 @Autowired 注解注入 DataSource 对象,然后获取连接进行测试,例如: ```java @RestController public class TestController { @Autowired private DataSource dataSource; @GetMapping("/test") public String test() throws SQLException { Connection conn = dataSource.getConnection(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT 1"); rs.next(); int result = rs.getInt(1); rs.close(); stmt.close(); conn.close(); return "Result: " + result; } } ``` 启动应用,访问 http://localhost:8080/test 进行测试,如果能输出 "Result: 1" 则说明连接配置成功。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

左左在右边

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值