Documentation Home
Connectors and APIs Manual
Download this Manual

4.4.2.3 SSH Connection Examples for X Protocol

The examples in this section demonstrates how to make X Protocol connections using standard TCP/IP over SSH:

Basic SSH Connection with Defaults

This example configures the SSH connection with a default value for the SSH port (22). However, because the connection uses X Protocol to establish the SSH tunnel, the default MySQL port (33060) is provided in the URI-like connection string.

using (var session = MySQLX.GetSession("mysqlx://myUser:test@localhost:33060?sshHostName=10.0.0.2;
                      sshUserName=mySshUser;sshPassword=sshTest"))
{
    session.Close();
}
SSH Connection With SSL Mode

This example creates the SSH tunnel for an anonymous object and it ensures that the use of SSL by denying the connection explicitly if the server does not support SSL.

var sessionOptions = {
    UserID = "myUser",
    Password = "test",
    Server = "127.0.0.1",
    Port = 3307,
    SshHostName = "10.0.0.2",
    SshUserName = "mySshUser",
    SshKeyFile = @"C:\keys\myOpenSshKeyFile.ppk",
    SshPassPhrase = "sshtest",
    SslMode = MySqlSslMode.Required
  };
using (var session = MySQLX.GetSession(sessionOptions))
{
    session.Close();
}