Documentation Home
X DevAPI User Guide
Download this Manual
PDF (US Ltr) - 1.4Mb
PDF (A4) - 1.4Mb

X DevAPI User Guide  /  ...  /  Connections Using DNS SRV Records

2.2.4 Connections Using DNS SRV Records

X DevAPI supports the use of DNS SRV records for connecting to MySQL 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. This section focuses on use of DNS SRV within X DevAPI applications. For general information about DNS SRV support in MySQL, see Connecting to the Server Using DNS SRV Records.

MySQL Connectors that implement X DevAPI can request DNS SRV record lookup by specifying mysqlx+srv as the scheme element of the URI-like connection string, along with the DNS SRV name. For example:


A DNS SRV name consists of a service, protocol, and domain, with the service and protocol each prefixed by an underscore. In the example, mysqlx indicates the X Protocol service and tcp indicates the TCP protocol.

The X DevAPI mysqlx.getSession() method, and the mysqlx.getClient() method for connection pooling, validate connection information with this protocol scheme extension, and handle the resulting DNS SRV record as a list of hosts for the purposes of failover behavior and connection pooling. The priority and weighting specified in the DNS SRV record is respected.

MySQL Connectors also have connector-specific options to request DNS SRV record lookup both for X Protocol connections and for classic MySQL protocol connections. For details, see the documentation for individual MySQL Connectors.


MySQL Shell does not currently support DNS SRV records.

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

  • The request must specify the full DNS SRV record name, with the service and protocol names prefixed by underscores. For example, this DNS SRV record relates to an X Protocol service implemented over TCP that can be provided by multiple servers in the installation:

    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

    A client can specify that DNS SRV record using syntax like this:

    var client = mysqlx.getClient("mysqlx+srv://")
  • The request must not specify multiple host names.

  • The request must not specify a port number.

  • Only TCP connections are supported. Unix socket files, Windows named pipes, and shared memory cannot be used.

Java Code

Session mySession = new 

Node.js JavaScript Code

mysqlx.getSession({ host: '', resolveSrv: true })

C# Code

var session = MySQLX.GetSession("mysqlx+srv://");

Connector/C++ Code using X DevAPI for C

mysqlx::Session sess(
    SessionOption::HOST, "",
    SessionOption::DNS_SRV, true,
    SessionOption::USER, "user",
    SessionOption::PWD, "password");

Python Code

session = mysqlx.get_session(host="", dns_srv=True)