Documentation Home
Connectors and APIs Manual
Download this Manual
PDF (US Ltr) - 4.1Mb
PDF (A4) - 4.1Mb


Connectors and APIs Manual  /  ...  /  Support for DNS SRV Records

3.5.14 Support for DNS SRV Records

Connector/J supports the use of DNS SRV records for connections since release 8.0.19. For information about DNS SRV support in MySQL, see Connecting to the Server Using DNS SRV Records.

When multiple MySQL instances provide the same service for your applications, DNS SRV records can be used to provide failover, load balancing, and replication services. They eliminate the need for clients to identify each possible host in the connection string, or for connections to be handled by an additional software component. Here is a summary for Connector/J's support for DNS SRV records:

  • These new schemas in the connection URLs enable DNS SRV record support:

    • jdbc:mysql+srv: For ordinary and basic failover JDBC connections that make use of DNS SRV records.

    • jdbc:mysql+srv:loadbalance: For load-balancing JDBC connections that make use of DNS SRV records.

    • jdbc:mysql+srv:replication: For replication JDBC connections that make use of DNS SRV records.

    • mysqlx+srv: For X DevAPI connections that make use of DNS SRV records.

  • Besides using the new schemas in the connection URLs, DNS SRV record support can be enabled or disabled using the two new connection properties, dnsSrv and xdevapi.dns-srv, for JDBC and X DevAPI connections respectively. For example, this connection URL enables DNS SRV record support:

    mysqlx://johndoe:secret@_mysql._tcp.mycompany.local/db?xdevapi.dns-srv=true

    However, using the DNS SRV schema with the DNS SRV connection properties set to false results in an error; for example:

    mysqlx+srv://johndoe:secret@_mysql._tcp.mycompany.local/db?xdevapi.dns-srv=false 
    # The connection URL causes Connector/J to throw an error

Here are some requirements and restrictions on the DNS SRV record support by Connector/J:

  • Connector/J throws an exception if multiple hosts are specified in the connection URL for a DNS SRV connection (except for a replication set up, created using jdbc:mysql+srv:replication, which requires exactly one source and one replica server to be specified).

  • Connector/J throws an exception if a port number is specified in the connection URL for a DNS SRV connection.

  • DNS SRV records are supported only for TCP/IP connections. Connector/J throws an exception if you attempt to enable DNS SRV record support Windows named pipe connections.

DNS SRV Record Support for Load Balancing and Failover.  For load-balancing and failover connections, Connector/J uses the priority field of the DNS SRV records to decide on the priorities for connection attempts for hosts.

DNS SRV Record Support for Connection Pooling.  In an X DevAPI connection pooling setup, Connector/J re-queries the DNS SRV records regularly and phases out gracefully any connections whose hosts no longer appear in the records, and readmits the connections into the pool when their hosts reappear in the records.

Looking up DNS SRV Records.  It is the users' responsibility to provide a full service host name; Connector/J does not append any prefix nor validate the host name structure. The following are examples of valid service host name patterns:

  • foo.domain.local

  • _mysql._tcp.foo.domain.local

  • _mysqlx._tcp.foo.domain.local

  • _readonly._tcp.foo.domain.local

  • _readwrite._tcp.foo.domain.local

See Connections Using DNS SRV Records in the X DevAPI User Guide for details.