配置属性定义 Connector/J 将如何连接到 MySQL 服务器。除非另有说明,否则可以为DataSource对象或
        Connection对象设置属性。
      
可以通过以下方式之一设置配置属性:
- 
使用 set*()MySQL 实现上的方法java.sql.DataSource(这是使用 的实现时的首选方法java.sql.DataSource):- com.mysql.cj.jdbc.MysqlDataSource
- com.mysql.cj.jdbc.MysqlConnectionPoolDataSource
 
- java.util.Properties作为传递给- DriverManager.getConnection()或 的实例中的键值对- Driver.connect()
- 
作为给定的 URL 中的 JDBC URL 参数 java.sql.DriverManager.getConnection(),java.sql.Driver.connect()或该javax.sql.DataSourcesetURL()方法的 MySQL 实现。如果您在 URL 中指定配置属性而没有为其提供值,则不会设置任何内容;例如,useServerPrepStmts单独添加到 URL 不会使 Connector/J 使用服务器端准备语句;你需要添加useServerPrepStmts=true.笔记如果用于配置 JDBC URL 的机制是基于 XML 的,请使用 XML 字符文字 &来分隔配置参数,因为 & 符号是 XML 的保留字符。
这些属性在下表中按类别列出,然后在后面的小节中列出。单击表中的属性名称可在小节中查看其完整描述。
表 6.1 身份验证属性
| 姓名 | 默认值 | 自版本 | 
|---|---|---|
| user | - | 所有版本 | 
| password | - | 所有版本 | 
| password1 | - | 8.0.28 | 
| password2 | - | 8.0.28 | 
| password3 | - | 8.0.28 | 
| authenticationPlugins | - | 5.1.19 | 
| disabledAuthenticationPlugins | - | 5.1.19 | 
| ociConfigFile | - | 8.0.27 | 
| authenticationFidoCallbackHandler | - | 8.0.29 | 
| defaultAuthenticationPlugin | mysql_native_password | 5.1.19 | 
| ldapServerHostname | - | 8.0.23 | 
表 6.2 连接属性
| 姓名 | 默认值 | 自版本 | 
|---|---|---|
| connectionAttributes | - | 5.1.25 | 
| connectionLifecycleInterceptors | - | 5.1.4 | 
| useConfigs | - | 3.1.5 | 
| clientInfoProvider | com.mysql.cj.jdbc.CommentClientInfoProvider | 5.1.0 | 
| createDatabaseIfNotExist | 错误的 | 3.1.9 | 
| databaseTerm | 目录 | 8.0.17 | 
| detectCustomCollations | 错误的 | 5.1.29 | 
| disconnectOnExpiredPasswords | 真的 | 5.1.23 | 
| interactiveClient | 错误的 | 3.1.0 | 
| passwordCharacterEncoding | - | 5.1.7 | 
| propertiesTransform | - | 3.1.4 | 
| rollbackOnPooledClose | 真的 | 3.0.15 | 
| useAffectedRows | 错误的 | 5.1.7 | 
表 6.3 会话属性
| 姓名 | 默认值 | 自版本 | 
|---|---|---|
| sessionVariables | - | 3.1.8 | 
| characterEncoding | - | 1.1克 | 
| characterSetResults | - | 3.0.13 | 
| connectionCollation | - | 3.0.13 | 
| customCharsetMapping | - | 8.0.26 | 
| trackSessionState | 错误的 | 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 | 错误的 | 8.0.19 | 
| localSocketAddress | - | 5.0.5 | 
| maxAllowedPacket | 65535 | 5.1.8 | 
| socksProxyRemoteDns | 错误的 | 8.0.29 | 
| tcpKeepAlive | 真的 | 5.0.7 | 
| tcpNoDelay | 真的 | 5.0.7 | 
| tcpRcvBuf | 0 | 5.0.7 | 
| tcpSndBuf | 0 | 5.0.7 | 
| tcpTrafficClass | 0 | 5.0.7 | 
| useCompression | 错误的 | 3.0.17 | 
| useUnbufferedInput | 真的 | 3.0.11 | 
表 6.5 安全属性
| 姓名 | 默认值 | 自版本 | 
|---|---|---|
| paranoid | 错误的 | 3.0.1 | 
| serverRSAPublicKeyFile | - | 5.1.31 | 
| allowPublicKeyRetrieval | 错误的 | 5.1.31 | 
| sslMode | 首选 | 8.0.13 | 
| trustCertificateKeyStoreUrl | - | 5.1.0 | 
| trustCertificateKeyStoreType | JKS | 5.1.0 | 
| trustCertificateKeyStorePassword | - | 5.1.0 | 
| fallbackToSystemTrustStore | 真的 | 8.0.22 | 
| clientCertificateKeyStoreUrl | - | 5.1.0 | 
| clientCertificateKeyStoreType | JKS | 5.1.0 | 
| clientCertificateKeyStorePassword | - | 5.1.0 | 
| fallbackToSystemKeyStore | 真的 | 8.0.22 | 
| tlsCiphersuites | - | 5.1.35 | 
| tlsVersions | - | 8.0.8 | 
| allowLoadLocalInfile | 错误的 | 3.0.3 | 
| allowLoadLocalInfileInPath | - | 8.0.22 | 
| allowMultiQueries | 错误的 | 3.1.1 | 
| allowUrlInLocalInfile | 错误的 | 3.1.4 | 
| requireSSL | 错误的 | 3.1.0 | 
| useSSL | 真的 | 3.0.2 | 
| verifyServerCertificate | 错误的 | 5.1.6 | 
表 6.6 语句属性
| 姓名 | 默认值 | 自版本 | 
|---|---|---|
| cacheDefaultTimeZone | 真的 | 8.0.20 | 
| continueBatchOnError | 真的 | 3.0.3 | 
| dontTrackOpenResources | 错误的 | 3.1.7 | 
| queryInterceptors | - | 8.0.7 | 
| queryTimeoutKillsConnection | 错误的 | 5.1.9 | 
表 6.7 准备好的语句属性
| 姓名 | 默认值 | 自版本 | 
|---|---|---|
| allowNanAndInf | 错误的 | 3.1.5 | 
| autoClosePStmtStreams | 错误的 | 3.1.12 | 
| compensateOnDuplicateKeyUpdateCounts | 错误的 | 5.1.7 | 
| emulateUnsupportedPstmts | 真的 | 3.1.7 | 
| generateSimpleParameterMetadata | 错误的 | 5.0.5 | 
| processEscapeCodesForPrepStmts | 真的 | 3.1.12 | 
| useServerPrepStmts | 错误的 | 3.1.0 | 
| useStreamLengthsInPrepStmts | 真的 | 3.0.2 | 
表 6.8 结果集属性
| 姓名 | 默认值 | 自版本 | 
|---|---|---|
| clobberStreamingResults | 错误的 | 3.0.9 | 
| emptyStringsConvertToZero | 真的 | 3.1.8 | 
| holdResultsOpenOverStatementClose | 错误的 | 3.1.7 | 
| jdbcCompliantTruncation | 真的 | 3.1.2 | 
| maxRows | -1 | 所有版本 | 
| netTimeoutForStreamingResults | 600 | 5.1.0 | 
| padCharsWithSpace | 错误的 | 5.0.6 | 
| populateInsertRowWithDefaultValues | 错误的 | 5.0.5 | 
| scrollTolerantForwardOnly | 错误的 | 8.0.24 | 
| strictUpdates | 真的 | 3.0.4 | 
| tinyInt1isBit | 真的 | 3.0.16 | 
| transformedBitIsBoolean | 错误的 | 3.1.9 | 
表 6.9 元数据属性
| 姓名 | 默认值 | 自版本 | 
|---|---|---|
| getProceduresReturnsFunctions | 真的 | 5.1.26 | 
| noAccessToProcedureBodies | 错误的 | 5.0.3 | 
| nullDatabaseMeansCurrent | 错误的 | 3.1.8 | 
| useHostsInPrivileges | 真的 | 3.0.2 | 
| useInformationSchema | 错误的 | 5.0.0 | 
表 6.10 BLOB/CLOB 处理属性
| 姓名 | 默认值 | 自版本 | 
|---|---|---|
| autoDeserialize | 错误的 | 3.1.5 | 
| blobSendChunkSize | 1048576 | 3.1.9 | 
| blobsAreStrings | 错误的 | 5.0.8 | 
| clobCharacterEncoding | - | 5.0.0 | 
| emulateLocators | 错误的 | 3.1.0 | 
| functionsNeverReturnBlobs | 错误的 | 5.0.8 | 
| locatorFetchBufferSize | 1048576 | 3.2.1 | 
表 6.11 日期时间类型处理属性
| 姓名 | 默认值 | 自版本 | 
|---|---|---|
| connectionTimeZone | - | 3.0.2 | 
| forceConnectionTimeZoneToSession | 错误的 | 8.0.23 | 
| noDatetimeStringSync | 错误的 | 3.1.7 | 
| preserveInstants | 真的 | 8.0.23 | 
| sendFractionalSeconds | 真的 | 5.1.37 | 
| sendFractionalSecondsForTime | 真的 | 8.0.23 | 
| treatUtilDateAsTimestamp | 真的 | 5.0.5 | 
| yearIsDateType | 真的 | 3.1.9 | 
| zeroDateTimeBehavior | 例外 | 3.1.4 | 
表 6.12 高可用性和集群属性
表 6.13 性能扩展属性
| 姓名 | 默认值 | 自版本 | 
|---|---|---|
| callableStmtCacheSize | 100 | 3.1.2 | 
| metadataCacheSize | 50 | 3.1.1 | 
| useLocalSessionState | 错误的 | 3.1.7 | 
| useLocalTransactionState | 错误的 | 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 | 真的 | 3.1.7 | 
| maintainTimeStats | 真的 | 3.1.9 | 
| useCursorFetch | 错误的 | 5.0.0 | 
| cacheCallableStmts | 错误的 | 3.1.2 | 
| cachePrepStmts | 错误的 | 3.0.10 | 
| cacheResultSetMetadata | 错误的 | 3.1.1 | 
| cacheServerConfiguration | 错误的 | 3.1.5 | 
| defaultFetchSize | 0 | 3.1.9 | 
| dontCheckOnDuplicateKeyUpdateInSQL | 错误的 | 5.1.32 | 
| elideSetAutoCommits | 错误的 | 3.1.3 | 
| enableEscapeProcessing | 真的 | 6.0.1 | 
| enableQueryTimeouts | 真的 | 5.0.6 | 
| largeRowSizeThreshold | 2048 | 5.1.1 | 
| readOnlyPropagatesToServer | 真的 | 5.1.35 | 
| rewriteBatchedStatements | 错误的 | 3.1.13 | 
| useReadAheadInput | 真的 | 3.1.5 | 
表 6.14 调试/分析属性
| 姓名 | 默认值 | 自版本 | 
|---|---|---|
| logger | com.mysql.cj.log.StandardLogger | 3.1.1 | 
| profilerEventHandler | com.mysql.cj.log.LoggingProfilerEventHandler | 5.1.6 | 
| useNanosForElapsedTime | 错误的 | 5.0.7 | 
| maxQuerySizeToLog | 2048 | 3.1.3 | 
| maxByteArrayAsHex | 1024 | 8.0.31 | 
| profileSQL | 错误的 | 3.1.0 | 
| logSlowQueries | 错误的 | 3.1.2 | 
| slowQueryThresholdMillis | 2000 | 3.1.2 | 
| slowQueryThresholdNanos | 0 | 5.0.7 | 
| autoSlowLog | 真的 | 5.1.4 | 
| explainSlowQueries | 错误的 | 3.1.2 | 
| gatherPerfMetrics | 错误的 | 3.1.2 | 
| reportMetricsIntervalMillis | 30000 | 3.1.2 | 
| logXaCommands | 错误的 | 5.0.5 | 
| traceProtocol | 错误的 | 3.1.2 | 
| enablePacketDebug | 错误的 | 3.1.3 | 
| packetDebugBufferSize | 20 | 3.1.3 | 
| useUsageAdvisor | 错误的 | 3.1.1 | 
| resultSetSizeThreshold | 100 | 5.0.5 | 
| autoGenerateTestcaseScript | 错误的 | 3.1.9 | 
表 6.15 异常/警告属性
| 姓名 | 默认值 | 自版本 | 
|---|---|---|
| dumpQueriesOnException | 错误的 | 3.1.3 | 
| exceptionInterceptors | - | 5.1.8 | 
| ignoreNonTxTables | 错误的 | 3.0.9 | 
| includeInnodbStatusInDeadlockExceptions | 错误的 | 5.0.7 | 
| includeThreadDumpInDeadlockExceptions | 错误的 | 5.1.15 | 
| includeThreadNamesAsStatementComment | 错误的 | 5.1.15 | 
| useOnlyServerErrorMessages | 真的 | 3.0.15 | 
表 6.16 用于与其他产品集成的 Tunes 属性
| 姓名 | 默认值 | 自版本 | 
|---|---|---|
| overrideSupportsIntegrityEnhancementFacility | 错误的 | 3.1.12 | 
| ultraDevHack | 错误的 | 2.0.3 | 
表 6.17 JDBC 合规性属性
| 姓名 | 默认值 | 自版本 | 
|---|---|---|
| useColumnNamesInFindColumn | 错误的 | 5.1.7 | 
| pedantic | 错误的 | 3.0.0 | 
| useOldAliasMetadataBehavior | 错误的 | 5.0.4 | 
表 6.18 X 协议和 X DevAPI 属性
| 姓名 | 默认值 | 自版本 | 
|---|---|---|
| xdevapi.auth | 清楚的 | 8.0.8 | 
| xdevapi.compression | 首选 | 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 | 错误的 | 8.0.19 | 
| xdevapi.fallback-to-system-keystore | 真的 | 8.0.22 | 
| xdevapi.fallback-to-system-truststore | 真的 | 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 | 必需的 | 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 |