MultiConnectMultiConnectDocs Website home
MultiConnectCloud › Database Deployments

6. Connect to your database

Where to find the connection details

Where What it shows
Connection section on the deployment's page Writer, Reader, SSL Mode, Database, Username, Replica Lag, Cache if you have one, and Storage used against the plan
Endpoints section on the deployment's page The deployment's addresses
CA Certificate section on the deployment's page The certificate file and ready-made connection strings for the writer and the reader
multiconnect info The same connection details in a terminal. See the CLI Guide
Integration Guide at the bottom of the deployment's page Working examples in C#, Java, Python, Go, Node.js, PHP and the shell, filled in with this deployment's hosts, ports, database and user

None of these shows the database password. Use the one you saved in Section 3.

Download the certificate file

Database certificates are signed by MultiConnectCloud's own certificate authority. Download its certificate once and point your client at it. It is a public file, the same for every database, and not a secret.

On the deployment's page, in the CA Certificate section, select Download multiconnect-db-ca.pem. To fetch it from a script or a server build instead:

Script 6.1: Download the certificate file

curl -fsSL https://api.multiconnectcloud.com/api/PublicNew/DatabaseCa/Download \
     -o /etc/ssl/certs/multiconnect-db-ca.pem

The file can hold more than one certificate. That is normal: while the certificate authority is being replaced, both the old and new certificates are in it. Active Certificate Expires in the same section shows when to download it again.

Use the strictest TLS mode, which checks the hostname as well as the certificate:

Engine Use this Not this
MySQL VERIFY_IDENTITY (SslMode=VerifyFull in .NET) VERIFY_CA, which does not check the hostname
PostgreSQL verify-full verify-ca, which does not check the hostname

Without the certificate file, the connection is still encrypted, but nothing proves the server is yours.

Connection strings

Copy the host and port from the Connection section. Read the password from an environment variable or a secret manager, never from your code. In each example, swap in the reader's host and port to make a read-only connection.

Script 6.2: MySQL connection string (.NET, MySqlConnector)

Server=<writer host>;Port=<writer port>;Database=appdb;User ID=appuser;Password=<your password>;SslMode=VerifyFull;SslCa=/etc/ssl/certs/multiconnect-db-ca.pem

Script 6.3: MySQL from the command line

mysql --host=<writer host> --port=<writer port> --user=appuser -p \
      --ssl-mode=VERIFY_IDENTITY --ssl-ca=/etc/ssl/certs/multiconnect-db-ca.pem \
      appdb

Script 6.4: PostgreSQL connection string (.NET, Npgsql)

Host=<writer host>;Port=<writer port>;Database=appdb;Username=appuser;Password=<your password>;SSL Mode=VerifyFull;Root Certificate=/etc/ssl/certs/multiconnect-db-ca.pem

Script 6.5: PostgreSQL from the command line

psql "host=<writer host> port=<writer port> dbname=appdb user=appuser sslmode=verify-full sslrootcert=/etc/ssl/certs/multiconnect-db-ca.pem"

Script 6.3 or 6.5 is the quickest way to prove that the endpoint, your allowed list and the certificate are all right.

Connection pools

Use a connection pool, and keep it small. Each plan has a connection limit, shown as Max Connections in the Plan section, and a pool of 20 on each of ten application servers is 200 connections whether or not they are busy.

A pool also makes a failover painless. Set a short connect timeout, a maximum connection lifetime of a few minutes, and retry connection errors, not query errors, a few times.