Documentation Home
MySQL Connector/J Developer Guide
Related Documentation Download this Manual
PDF (US Ltr) - 1.2Mb
PDF (A4) - 1.2Mb


6.3.3 Session

  • sessionVariables

    A comma or semicolon separated list of "name=value" pairs to be sent as "SET [SESSION] ..." to the server when the driver connects.

    Since Version 3.1.8
  • characterEncoding

    Instructs the server to set session system variables 'character_set_client' and 'character_set_connection' to the default character set supported by MySQL for the specified Java character encoding and set 'collation_connection' to the default collation for this character set. If neither this property nor the property 'connectionCollation' is set:

    For Connector/J 8.0.25 and earlier, the driver will try to use the server's default character set;

    For Connector/J 8.0.26 and later, the driver will use "utf8mb4".

    Since Version 1.1g
  • characterSetResults

    Instructs the server to return the data encoded with the default character set for the specified Java encoding. If not set or set to "null", the server will send data in its original character set and the driver will decode it according to the result metadata.

    Since Version 3.0.13
  • connectionCollation

    Instructs the server to set session system variable 'collation_connection' to the specified collation name and set 'character_set_client' and 'character_set_connection' to a corresponding character set. This property overrides the value of 'characterEncoding' with the default character set this collation belongs to, if and only if 'characterEncoding' is not configured or is configured with a character set that is incompatible with the collation. That means 'connectionCollation' may not always correct a mismatch of character sets. For example, if 'connectionCollation' is set to "latin1_swedish_ci", the corresponding character set is "latin1" for MySQL, which maps it to the Java character set "windows-1252"; so if 'characterEncoding' is not set,"windows-1252" is the character set that will be used; but if 'characterEncoding' has been set to, e.g. "ISO-8859-1", that is compatible with "latin1_swedish_ci", so the character encoding setting is left unchanged; and if client is actually using "windows-1252" (which is similar but different from "ISO-8859-1"), errors would occur for some characters. If neither this property nor the property 'characterEncoding' is set:

    For Connector/J 8.0.25 and earlier, the driver will try to use the server's default character set;

    For Connector/J 8.0.26 and later, the driver will use utf8mb4's default collation.

    Since Version 3.0.13
  • customCharsetMapping

    A comma-delimited list of custom "charset:java encoding" pairs.

    In case the MySQL server is configured with custom character sets and "detectCustomCollations=true", Connector/J needs to know which Java character encoding to use for the data represented by these character sets. Example usage: "customCharsetMapping=charset1:UTF-8,charset2:Cp1252".

    Since Version 8.0.26
  • trackSessionState

    Receive server session state changes on query results. These changes are accessible via 'MysqlConnection.getServerSessionStateController()'.

    Default Value false
    Since Version 8.0.26