X DevAPI User Guide

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):

Java Code

Session mySession = new 

Node.js JavaScript Code

mysqlx.getSession({ host: '_mysqlx._tcp.example.com', resolveSrv: true }) 

C# Code

var session = MySQLX.GetSession("mysqlx+srv://user:password@_mysqlx._tcp.example.com.");

Connector/C++ Code using X DevAPI for C

mysqlx::Session sess(
    SessionOption::HOST, "_mysqlx._tcp.example.com",
    SessionOption::DNS_SRV, true,
    SessionOption::USER, "user",
    SessionOption::PWD, "password");

Python Code

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