mysql+url的配置参数详解_MySql链接url参数详解
mysql URL格式如下:jdbc:mysql://[host:port],[host:port].../[database][?參數(shù)名1][=參數(shù)值1][&參數(shù)名2][=參數(shù)值2]...
MySQL在高版本需要指明是否進(jìn)行SSL連接 ?在url后面加上 ? ? useSSL=true ? 不然寫(xiě)程序會(huì)有warning
常用的幾個(gè)較為重要的參數(shù):
參數(shù)名稱 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 參數(shù)說(shuō)明
user ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 數(shù)據(jù)庫(kù)用戶名(用于連接數(shù)據(jù)庫(kù))
passWord ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 用戶密碼(用于連接數(shù)據(jù)庫(kù))
useUnicode ? ? ? ? ? ? ? ? ? ? ? ? ? ?是否使用Unicode字符集,如果參數(shù)characterEncoding設(shè)置為gb2312或gbk,本參數(shù)值必須設(shè)置為true
autoReconnect ? ? ? ? ? ? ? ? ? ? ? 當(dāng)數(shù)據(jù)庫(kù)連接異常中斷時(shí),是否自動(dòng)重新連接?
autoReconnectForPools ? ? ? ? ? 是否使用針對(duì)數(shù)據(jù)庫(kù)連接池的重連策略
maxReconnects ? ? ? ? ? ? ? ? ? ? ?autoReconnect設(shè)置為true時(shí),重試連接的次數(shù)
failOverReadOnly ? ? ? ? ? ? ? ? ? 自動(dòng)重連成功后,連接是否設(shè)置為只讀?
對(duì)應(yīng)中文環(huán)境,通常mysql連接URL可以設(shè)置為:
jdbc:mysql://localhost:3306/test?user=root&password=&useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
在使用數(shù)據(jù)庫(kù)連接池的情況下,最好設(shè)置如下兩個(gè)參數(shù):
autoReconnect=true&failOverReadOnly=false
需要注意的是,在xml配置文件中,url中的&符號(hào)需要轉(zhuǎn)義成&。比如在tomcat的server.xml中配置數(shù)據(jù)庫(kù)連接池時(shí),mysql jdbc url樣例如下:
jdbc:mysql://localhost:3306/test?user=root&password=&useUnicode=true&characterEncoding=utf8&autoReconnect=true
總結(jié)
以上是生活随笔為你收集整理的mysql+url的配置参数详解_MySql链接url参数详解的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: java外部类_Java里什么叫内部类什
- 下一篇: mysql 5.5.22.tar.gz_