組態屬性定義 Connector/J 如何連線至 MySQL 伺服器。除非另有說明,否則屬性可以針對 DataSource
物件或 Connection
物件進行設定。
組態屬性可以使用下列其中一種方式設定
-
在 MySQL 實作的
java.sql.DataSource
上使用set*()
方法 (當使用java.sql.DataSource
的實作時,這是較佳的方法)com.mysql.cj.jdbc.MysqlDataSource
com.mysql.cj.jdbc.MysqlConnectionPoolDataSource
做為傳遞至
DriverManager.getConnection()
或Driver.connect()
的java.util.Properties
執行個體中的鍵值組-
做為在傳遞至
java.sql.DriverManager.getConnection()
、java.sql.Driver.connect()
或javax.sql.DataSource
的 MySQL 實作的setURL()
方法的 URL 中的 JDBC URL 參數。如果您在 URL 中指定組態屬性,卻未提供值,則不會設定任何內容;例如,僅將useServerPrepStmts
新增至 URL 並不會讓 Connector/J 使用伺服器端預先處理的陳述式;您需要新增useServerPrepStmts=true
。注意如果您用來設定 JDBC URL 的機制是以 XML 為基礎,請使用 XML 字元常值
&
來分隔組態參數,因為 & 符號是 XML 的保留字元。
這些屬性會依類別列在下列表格中,然後列在後面的小節中。按一下表格中的屬性名稱,即可在小節中查看其完整說明。
表 6.1 驗證屬性
名稱 | 預設值 | 自版本 |
---|---|---|
使用者 |
- | 所有版本 |
密碼 |
- | 所有版本 |
密碼 1
|
- | 8.0.28 |
密碼 2
|
- | 8.0.28 |
密碼 3
|
- | 8.0.28 |
authenticationPlugins |
- | 5.1.19 |
disabledAuthenticationPlugins |
- | 5.1.19 |
defaultAuthenticationPlugin |
caching_sha2_password | 5.1.19 |
ldapServerHostname |
- | 8.0.23 |
ociConfigFile |
- | 8.0.27 |
ociConfigProfile |
預設 | 8.0.33 |
authenticationWebAuthnCallbackHandler |
- | 8.2.0 |
表 6.2 連線屬性
名稱 | 預設值 | 自版本 |
---|---|---|
connectionAttributes |
- | 5.1.25 |
connectionLifecycleInterceptors |
- | 5.1.4 |
useConfigs
|
- | 3.1.5 |
clientInfoProvider |
com.mysql.cj.jdbc.CommentClientInfoProvider | 5.1.0 |
createDatabaseIfNotExist |
false | 3.1.9 |
databaseTerm
|
CATALOG | 8.0.17 |
detectCustomCollations |
false | 5.1.29 |
disconnectOnExpiredPasswords |
true | 5.1.23 |
interactiveClient |
false | 3.1.0 |
passwordCharacterEncoding |
- | 5.1.7 |
propertiesTransform |
- | 3.1.4 |
rollbackOnPooledClose |
true | 3.0.15 |
useAffectedRows |
false | 5.1.7 |
表 6.3 工作階段屬性
名稱 | 預設值 | 自版本 |
---|---|---|
sessionVariables |
- | 3.1.8 |
characterEncoding |
- | 1.1g |
characterSetResults |
- | 3.0.13 |
connectionCollation |
- | 3.0.13 |
customCharsetMapping |
- | 8.0.26 |
trackSessionState |
false | 8.0.26 |
表 6.4 網路屬性
名稱 | 預設值 | 自版本 |
---|---|---|
socksProxyHost |
- | 5.1.34 |
socksProxyPort |
1080 | 5.1.34 |
socketFactory |
com.mysql.cj.protocol.StandardSocketFactory | 3.0.3 |
connectTimeout |
0 | 3.0.1 |
socketTimeout |
0 | 3.0.1 |
dnsSrv |
false | 8.0.19 |
localSocketAddress |
- | 5.0.5 |
maxAllowedPacket |
65535 | 5.1.8 |
socksProxyRemoteDns |
false | 8.0.29 |
tcpKeepAlive
|
true | 5.0.7 |
tcpNoDelay
|
true | 5.0.7 |
tcpRcvBuf
|
0 | 5.0.7 |
tcpSndBuf
|
0 | 5.0.7 |
tcpTrafficClass |
0 | 5.0.7 |
useCompression |
false | 3.0.17 |
useUnbufferedInput |
true | 3.0.11 |
表 6.5 安全性屬性
名稱 | 預設值 | 自版本 |
---|---|---|
paranoid |
false | 3.0.1 |
serverRSAPublicKeyFile |
- | 5.1.31 |
allowPublicKeyRetrieval |
false | 5.1.31 |
sslMode |
PREFERRED | 8.0.13 |
trustCertificateKeyStoreUrl |
- | 5.1.0 |
trustCertificateKeyStoreType |
JKS | 5.1.0 |
trustCertificateKeyStorePassword |
- | 5.1.0 |
fallbackToSystemTrustStore |
true | 8.0.22 |
clientCertificateKeyStoreUrl |
- | 5.1.0 |
clientCertificateKeyStoreType |
JKS | 5.1.0 |
clientCertificateKeyStorePassword |
- | 5.1.0 |
fallbackToSystemKeyStore |
true | 8.0.22 |
tlsCiphersuites |
- | 5.1.35 |
tlsVersions
|
- | 8.0.8 |
fipsCompliantJsse |
false | 8.1.0 |
KeyManagerFactoryProvider |
- | 8.1.0 |
trustManagerFactoryProvider |
- | 8.1.0 |
keyStoreProvider |
- | 8.1.0 |
sslContextProvider |
- | 8.1.0 |
allowLoadLocalInfile |
false | 3.0.3 |
allowLoadLocalInfileInPath |
- | 8.0.22 |
allowMultiQueries |
false | 3.1.1 |
allowUrlInLocalInfile |
false | 3.1.4 |
requireSSL
|
false | 3.1.0 |
useSSL |
true | 3.0.2 |
verifyServerCertificate |
false | 5.1.6 |
表 6.6 陳述式屬性
名稱 | 預設值 | 自版本 |
---|---|---|
cacheDefaultTimeZone |
true | 8.0.20 |
continueBatchOnError |
true | 3.0.3 |
dontTrackOpenResources |
false | 3.1.7 |
queryInterceptors |
- | 8.0.7 |
queryTimeoutKillsConnection |
false | 5.1.9 |
表 6.7 預先處理的陳述式屬性
名稱 | 預設值 | 自版本 |
---|---|---|
allowNanAndInf |
false | 3.1.5 |
autoClosePStmtStreams |
false | 3.1.12 |
compensateOnDuplicateKeyUpdateCounts |
false | 5.1.7 |
emulateUnsupportedPstmts |
true | 3.1.7 |
generateSimpleParameterMetadata |
false | 5.0.5 |
processEscapeCodesForPrepStmts |
true | 3.1.12 |
useServerPrepStmts |
false | 3.1.0 |
useStreamLengthsInPrepStmts |
true | 3.0.2 |
表 6.8 結果集屬性
名稱 | 預設值 | 自版本 |
---|---|---|
clobberStreamingResults |
false | 3.0.9 |
emptyStringsConvertToZero |
true | 3.1.8 |
holdResultsOpenOverStatementClose |
false | 3.1.7 |
jdbcCompliantTruncation |
true | 3.1.2 |
maxRows |
-1 | 所有版本 |
netTimeoutForStreamingResults |
600 | 5.1.0 |
padCharsWithSpace |
false | 5.0.6 |
populateInsertRowWithDefaultValues |
false | 5.0.5 |
scrollTolerantForwardOnly |
false | 8.0.24 |
strictUpdates |
true | 3.0.4 |
tinyInt1isBit |
true | 3.0.16 |
transformedBitIsBoolean |
false | 3.1.9 |
表 6.9 中繼資料屬性
名稱 | 預設值 | 自版本 |
---|---|---|
getProceduresReturnsFunctions |
true | 5.1.26 |
noAccessToProcedureBodies |
false | 5.0.3 |
nullDatabaseMeansCurrent |
false | 3.1.8 |
useHostsInPrivileges |
true | 3.0.2 |
useInformationSchema |
false | 5.0.0 |
表 6.10 BLOB/CLOB 處理屬性
名稱 | 預設值 | 自版本 |
---|---|---|
blobSendChunkSize |
1048576 | 3.1.9 |
blobsAreStrings |
false | 5.0.8 |
clobCharacterEncoding |
- | 5.0.0 |
emulateLocators |
false | 3.1.0 |
functionsNeverReturnBlobs |
false | 5.0.8 |
locatorFetchBufferSize |
1048576 | 3.2.1 |
表 6.11 日期時間類型處理屬性
名稱 | 預設值 | 自版本 |
---|---|---|
connectionTimeZone |
- | 3.0.2 |
forceConnectionTimeZoneToSession |
false | 8.0.23 |
noDatetimeStringSync |
false | 3.1.7 |
preserveInstants |
true | 8.0.23 |
sendFractionalSeconds |
true | 5.1.37 |
sendFractionalSecondsForTime |
true | 8.0.23 |
treatMysqlDatetimeAsTimestamp |
false | 8.2.0 |
treatUtilDateAsTimestamp |
true | 5.0.5 |
yearIsDateType |
true | 3.1.9 |
zeroDateTimeBehavior |
例外狀況 | 3.1.4 |
表 6.12 高可用性和叢集屬性
表 6.13 效能擴充屬性
名稱 | 預設值 | 自版本 |
---|---|---|
callableStmtCacheSize |
100 | 3.1.2 |
metadataCacheSize |
50 | 3.1.1 |
useLocalSessionState |
false | 3.1.7 |
useLocalTransactionState |
false | 5.1.7 |
prepStmtCacheSize |
25 | 3.0.10 |
prepStmtCacheSqlLimit |
256 | 3.0.10 |
queryInfoCacheFactory |
com.mysql.cj.PerConnectionLRUFactory | 5.1.1 |
serverConfigCacheFactory |
com.mysql.cj.util.PerVmServerConfigCacheFactory | 5.1.1 |
alwaysSendSetIsolation |
true | 3.1.7 |
maintainTimeStats |
true | 3.1.9 |
useCursorFetch |
false | 5.0.0 |
cacheCallableStmts |
false | 3.1.2 |
cachePrepStmts |
false | 3.0.10 |
cacheResultSetMetadata |
false | 3.1.1 |
cacheServerConfiguration |
false | 3.1.5 |
defaultFetchSize |
0 | 3.1.9 |
dontCheckOnDuplicateKeyUpdateInSQL |
false | 5.1.32 |
elideSetAutoCommits |
false | 3.1.3 |
enableEscapeProcessing |
true | 6.0.1 |
enableQueryTimeouts |
true | 5.0.6 |
largeRowSizeThreshold |
2048 | 5.1.1 |
readOnlyPropagatesToServer |
true | 5.1.35 |
rewriteBatchedStatements |
false | 3.1.13 |
useReadAheadInput |
true | 3.1.5 |
表 6.14 除錯/效能分析屬性
名稱 | 預設值 | 自版本 |
---|---|---|
logger |
com.mysql.cj.log.StandardLogger | 3.1.1 |
profilerEventHandler |
com.mysql.cj.log.LoggingProfilerEventHandler | 5.1.6 |
useNanosForElapsedTime |
false | 5.0.7 |
maxQuerySizeToLog |
2048 | 3.1.3 |
maxByteArrayAsHex |
1024 | 8.0.31 |
profileSQL
|
false | 3.1.0 |
logSlowQueries |
false | 3.1.2 |
slowQueryThresholdMillis |
2000 | 3.1.2 |
slowQueryThresholdNanos |
0 | 5.0.7 |
autoSlowLog
|
true | 5.1.4 |
explainSlowQueries |
false | 3.1.2 |
gatherPerfMetrics |
false | 3.1.2 |
reportMetricsIntervalMillis |
30000 | 3.1.2 |
logXaCommands |
false | 5.0.5 |
traceProtocol |
false | 3.1.2 |
enablePacketDebug |
false | 3.1.3 |
packetDebugBufferSize |
20 | 3.1.3 |
useUsageAdvisor |
false | 3.1.1 |
resultSetSizeThreshold |
100 | 5.0.5 |
autoGenerateTestcaseScript |
false | 3.1.9 |
openTelemetry |
PREFERRED | 8.4.0 |
表 6.15 例外/警告屬性
名稱 | 預設值 | 自版本 |
---|---|---|
dumpQueriesOnException |
false | 3.1.3 |
exceptionInterceptors |
- | 5.1.8 |
ignoreNonTxTables |
false | 3.0.9 |
includeInnodbStatusInDeadlockExceptions |
false | 5.0.7 |
includeThreadDumpInDeadlockExceptions |
false | 5.1.15 |
includeThreadNamesAsStatementComment |
false | 5.1.15 |
useOnlyServerErrorMessages |
true | 3.0.15 |
表 6.16 與其他產品整合的調整屬性
名稱 | 預設值 | 自版本 |
---|---|---|
overrideSupportsIntegrityEnhancementFacility
|
false | 3.1.12 |
ultraDevHack
|
false | 2.0.3 |
表 6.17 JDBC 相容性屬性
名稱 | 預設值 | 自版本 |
---|---|---|
useColumnNamesInFindColumn |
false | 5.1.7 |
pedantic |
false | 3.0.0 |
useOldAliasMetadataBehavior |
false | 5.0.4 |
表 6.18 X Protocol 和 X DevAPI 屬性
名稱 | 預設值 | 自版本 |
---|---|---|
xdevapi.auth
|
PLAIN | 8.0.8 |
xdevapi.compression |
PREFERRED | 8.0.20 |
xdevapi.compression-algorithms |
zstd_stream,lz4_message,deflate_stream | 8.0.22 |
xdevapi.compression-extensions |
- | 8.0.22 |
xdevapi.connect-timeout |
10000 | 8.0.13 |
xdevapi.connection-attributes |
- | 8.0.16 |
xdevapi.dns-srv |
false | 8.0.19 |
xdevapi.fallback-to-system-keystore |
true | 8.0.22 |
xdevapi.fallback-to-system-truststore |
true | 8.0.22 |
xdevapi.ssl-keystore |
- | 8.0.22 |
xdevapi.ssl-keystore-password |
- | 8.0.22 |
xdevapi.ssl-keystore-type |
JKS | 8.0.22 |
xdevapi.ssl-mode |
REQUIRED | 8.0.7 |
xdevapi.ssl-truststore |
- | 6.0.6 |
xdevapi.ssl-truststore-password |
- | 6.0.6 |
xdevapi.ssl-truststore-type |
JKS | 6.0.6 |
xdevapi.tls-ciphersuites |
- | 8.0.19 |
xdevapi.tls-versions |
- | 8.0.19 |