Connecting to a Cluster

Overview

You can connect to MySQL clusters through IP and DNS addresses. 6033 is a port for connecting to ProxySQL, which will automatically distribute requests between the cluster nodes.

There are several ways to connect to a cluster:

  • through the MySQL terminal program mysql;
  • using graphical tools (phpMyAdmin, MySQL Workbench, Sequel Pro, etc.) to manage databases;
  • from your app using one of the available language interfaces.

You can use an SSL certificate in all cases.

Connection for Linux

Using SSL

mkdir -p ~/.mysql/
wget https://storage.dbaas.selcloud.ru/CA.pem -O ~/.mysql/root.crt
chmod 0600 ~/.mysql/root.crt
mysql --host=<target_host> \
      --port=6033 \
      --user=<database user name> \
      --password \
      --database=<database name> \
      --ssl-ca=~/.mysql/root.crt \
      --ssl-mode=verify_ca

Without Using SSL

mysql --host=<target_host> \
      --port=6033 \
      --user=<database user name> \
      --password \
      --database=<database name> \
      --ssl-mode=disabled

Connection for Windows

Using SSL

Download the selcloud certificate.

When connecting, specify the location of the certificate using the --ssl-ca parameter:

mysql --host=<target_host> \
      --port=6033 \
      --user=<database user name> \
      --password \
      --database=<database name> \
      --ssl-ca=<cert path> \
      --ssl-mode=verify_ca

Without Using SSL

mysql --host=<target_host> \
      --port=6033 \
      --user=<database user name> \
      --password \
      --database=<database name> \
      --ssl-mode=disabled

Connection Using the Program Code

An example of connection for Python Using SSL (MySQL Connector driver)

import mysql.connector
cnx = mysql.connector.connect(user='username', password='password',
                              host='ip_or_fqdn',
                              database='database',
                              ssl_ca='path_to_ca_cert',
                              ssl_verify_cert=true)
cnx.close()

An example of connection for Python without Using SSL (MySQL Connector driver)

import mysql.connector
cnx = mysql.connector.connect(user='username', password='password',
                              host='ip_or_fqdn',
                              database='database')
cnx.close()