遇到一個(gè)問(wèn)題
關(guān)鍵點(diǎn):
You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
翻譯一下:
CST 2022 WARN:不建議在沒(méi)有服務(wù)器身份驗(yàn)證的情況下建立SSL連接。 根據(jù)MySQL 5.5.45+、5.6.26+和5.7.6+的要求,如果沒(méi)有設(shè)置顯式選項(xiàng),默認(rèn)必須建立SSL連接。 為了符合不使用SSL的現(xiàn)有應(yīng)用程序,verifyServerCertificate屬性被設(shè)置為’false’。 您需要通過(guò)設(shè)置useSSL=false
顯式禁用SSL,或者設(shè)置useSSL=true并為服務(wù)器證書(shū)驗(yàn)證提供信任存儲(chǔ)區(qū)。
解決:
找到數(shù)據(jù)庫(kù)和項(xiàng)目連接的配置文件
application-prod.properties
spring.datasource.url=jdbc:mysql://localhost:3306/life_vest?useUnicode=true&characterEncoding=UTF8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&useSSL=false
//原來(lái):
//spring.datasource.url=jdbc:mysql://127.0.0.1:3306/life_vest?useUnicode=true&characterEncoding=utf-8
試錯(cuò):
直接添加&useSSL=false
,沒(méi)有效果
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/life_vest?useUnicode=true&characterEncoding=utf-8&useSSL=false
或者
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/life_vest?useSSL=false&useUnicode=true&characterEncoding=utf-8
查到的資料
第一種處理辦法
jdbcUrl=jdbc:mysql://localhost:3306/zht?useUnicode=true&characterEncoding=utf-8&useSSL=false
1.先將mysql-connector-java的版本改到5.5.45之下
2.再將jdbcUrl改成如下
jdbcUrl=jdbc:mysql://localhost:3306/zht?useUnicode=true&characterEncoding=utf-8
第二種處理辦法
如果你覺(jué)得更喜歡5.5.45以后的版本,那么需要將jdbc.properties里jdbcUrl換成新的:
jdbc:mysql://localhost:3306/zht?useUnicode=true&characterEncoding=UTF8&autoReconnect=true&zeroDateTimeBehavior=convertToNull
參數(shù)名稱(chēng) | 參數(shù)說(shuō)明
user | 數(shù)據(jù)庫(kù)用戶(hù)名(用于連接數(shù)據(jù)庫(kù))
password | 用戶(hù)密碼(用于連接數(shù)據(jù)庫(kù))
useUnicode | 是否使用Unicode字符集,如果參數(shù)characterEncoding | 設(shè)置為gb2312或gbk,本參數(shù)值必須設(shè)置為true
characterEncoding | 當(dāng)useUnicode設(shè)置為true時(shí),指定字符編碼。比如可設(shè)置為gb2312或gbk
autoReconnect | 當(dāng)數(shù)據(jù)庫(kù)連接異常中斷時(shí),是否自動(dòng)重新連接?
autoReconnectForPools | 是否使用針對(duì)數(shù)據(jù)庫(kù)連接池的重連策略
failOverReadOnly | 自動(dòng)重連成功后,連接是否設(shè)置為只讀?
maxReconnects | autoReconnect設(shè)置為true時(shí),重試連接的次數(shù)
initialTimeout | autoReconnect設(shè)置為true時(shí),兩次重連之間的時(shí)間間隔,單位:秒
connectTimeout | 和數(shù)據(jù)庫(kù)服務(wù)器建立socket連接時(shí)的超時(shí),單位:毫秒。 0表示永不超時(shí),適用于JDK 1.4及更高版本
socketTimeout | socket操作(讀寫(xiě))超時(shí),單位:毫秒。 0表示永不超時(shí)
附錄:
完整application-prod.properties
阿里云 配置springboot與mysql數(shù)據(jù)庫(kù)
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/life_vest?useUnicode=true&characterEncoding=UTF8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&useSSL=false
//數(shù)據(jù)庫(kù)名稱(chēng)
spring.datasource.username=root
//數(shù)據(jù)庫(kù)密碼
spring.datasource.password=
//指定啟動(dòng)連接池時(shí),初始建立的連接數(shù)量
spring.datasource.initialSize=5
//指定必須保持連接的最小值(For DBCP and Tomcat connection pools)
spring.datasource.minIdle=5
//指定連接池中最大的活躍連接數(shù).
spring.datasource.maxActive=20
//指定連接池等待連接返回的最大等待時(shí)間,毫秒單位.
spring.datasource.maxWait=60000
//指定空閑連接檢查、廢棄連接清理、空閑連接池大小調(diào)整之間的操作時(shí)間間隔
spring.datasource.timeBetweenEvictionRunsMillis=60000
//指定一個(gè)空閑連接最少空閑多久后可被清除.
spring.datasource.minEvictableIdleTimeMillis=300000
//指定獲取連接時(shí)連接校驗(yàn)的sql查詢(xún)語(yǔ)句.
spring.datasource.validationQuery=SELECT 1 FROM DUAL
//當(dāng)連接空閑時(shí),是否執(zhí)行連接測(cè)試.
spring.datasource.testWhileIdle=true
//當(dāng)從連接池借用連接時(shí),是否測(cè)試該連接.
spring.datasource.testOnBorrow=false
//在連接歸還到連接池時(shí)是否測(cè)試該連接.
spring.datasource.testOnReturn=false
//指定是否池化statements.
spring.datasource.poolPreparedStatements=true
//
spring.datasource.maxPoolPreparedStatementPerConnectionSize=20
//
spring.datasource.filters=stat,wall,log4j
//在使用DBCP connection pool時(shí)指定要配置的屬性
spring.datasource.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
本地的話(huà)可以改成
jdbc:mysql://192.16.30.40:3306/life_vest
參考:
mysql 建立SSL連接問(wèn)題,設(shè)置useSSL=false顯式禁用SSL,或者設(shè)置useSSL=true文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-400836.html
springboot配置mysql數(shù)據(jù)庫(kù)spring.datasource.url報(bào)錯(cuò)的解決文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-400836.html
到了這里,關(guān)于You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!