MySQL连接参数

       前言

        MySQL数据库的连接方式、参数以及url配置参数大全


连接MySQL5.5
driver=com.mysql.jdbc.Driver 
url=jdbc:mysql://localhost:3306/test
username=root
password=root

连接MySQL6.0以上
driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/test?characterEncoding=utf8&useSSL=false&serverTimezone=UTC
username=root
password=root

url中重要参数设置
参数名 参数介绍 缺省值
useUnicode 是否使用Unicode字符集,如果参数characterEncoding设置为gb2312或gbk,本参数值必须设置为true false
characterEncoding 当useUnicode设置为true时,指定字符编码。比如可设置为gb2312或gbk,utf8 false
autoReconnect 当数据库连接异常中断时,是否自动重新连接? false
autoReconnectForPools 是否使用针对数据库连接池的重连策略 false
failOverReadOnly 自动重连成功后,连接是否设置为只读? true
maxReconnectsautoReconnect 设置为true时,重试连接的次数 3
initialTimeoutautoReconnect 置为true时,两次重连之间的时间间隔,单位:秒 2
connectTimeout 和数据库服务器建立socket连接时的超时,单位:毫秒。 0表示永不超时,适用于JDK 1.4以上 0
socketTimeoutsocket 操作(读写)超时,单位:毫秒。 0表示永不超时 0
verifyServerCertificate 如果强制要求设置SSL模式,将verifyServerCertificate设置为false,将不需要设置SSL false
useSSL 是否开启SSL模式连接 false
useJDBCCompliantTimezoneShift 是否开启JDBC时区设置 false
serverTimezone 设置时区:如:HongKong、ShangHai、UTC UTC