MySQL 8.0 Reference Manual Including MySQL NDB Cluster 8.0

6.2.6 Connecting to the Server Using DNS SRV Records

In the Domain Name System (DNS), a SRV record (service location record) is a type of resource record that enables a client to specify a name that indicates a service, protocol, and domain. A DNS lookup on the name returns a reply containing the names of multiple available servers in the domain that provide the required service. For information about DNS SRV, including how a record defines the preference order of the listed servers, see RFC 2782.

MySQL supports the use of DNS SRV records for connecting to servers. A client that receives a DNS SRV lookup result attempts to connect to the MySQL server on each of the listed hosts in order of preference, based on the priority and weighting assigned to each host by the DNS administrator. A failure to connect occurs only if the client cannot connect to any of the servers.

When multiple MySQL instances, such as a cluster of servers, provide the same service for your applications, DNS SRV records can be used to assist with failover, load balancing, and replication services. It is cumbersome for applications to directly manage the set of candidate servers for connection attempts, and DNS SRV records provide an alternative:

MySQL supports use of DNS SRV records to connect to servers in these contexts:

A DNS SRV name consists of a service, protocol, and domain, with the service and protocol each prefixed by an underscore:


The following DNS SRV record identifies multiple candidate servers, such as might be used by clients for establishing X Protocol connections:

Name                      TTL   Class  Priority Weight Port  Target 86400 IN SRV 0        5      33060 86400 IN SRV 0        10     33060 86400 IN SRV 10       5      33060 86400 IN SRV 20       5      33060

Here, mysqlx indicates the X Protocol service and tcp indicates the TCP protocol. A client can request this DNS SRV record using the name The particular syntax for specifying the name in the connection request depends on the type of client. For example, a client might support specifying the name within a URI-like connection string or as a key-value pair.

A DNS SRV record for classic protocol connections might look like this:

Name                     TTL   Class  Priority Weight  Port Target 86400 IN SRV 0        5       3306 86400 IN SRV 0        10      3306 86400 IN SRV 10       5       3306 86400 IN SRV 20       5       3306

Here, the name mysql designates the classic MySQL protocol service, and the port is 3306 (the default classic MySQL protocol port) rather than 33060 (the default X Protocol port).

When DNS SRV record lookup is used, clients generally must apply these rules for connection requests (there may be client- or connector-specific exceptions):

For more information on using DNS SRV based connections in X DevAPI, see Connections Using DNS SRV Records.