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