Skip to content

Connect to a DBaaS instance

View as Markdown

Connect to a DBaaS instance from a command-line client or from your application, using the connection details on its details page.

Have the DBaaS instance Running, and its current password to hand.

On the DBaaS instance’s details page, under Connection Details, note its Endpoint, Username, Port, and Database Name. If you have lost the password, see Reset the DBaaS instance password.

Choose the address to connect to:

  • Use Endpoint to connect from the internet, from any IP address the whitelist allows. It works while the Public IP row shows Attached. If the row shows Detached, click Attach and confirm with Attach.
  • Use Private IPv4 to connect from something inside a VPC attached to the DBaaS instance.
mysql -h <endpoint> -P 3306 -u <username> -p

<endpoint> is the Endpoint or Private IPv4 you chose, and <username> is the Username under Connection Details. Enter the password when asked. The client needs to use SSL; if it connects without SSL and is refused, use the SSL command in Connect with SSL on.

psql -h <endpoint> -p 5432 -U <username> -d <database-name>

<endpoint> is the Endpoint or Private IPv4 you chose, and <username> and <database-name> are the Username and Database Name under Connection Details. Enter the password when asked. The client needs to use SSL; if it connects without SSL and is refused, use the SSL command in Connect with SSL on.

Most drivers and object-relational mappers accept a connection URL instead of separate fields:

mysql://<username>:<password>@<endpoint>:3306/<database-name>
postgresql://<username>:<password>@<endpoint>:5432/<database-name>

Replace <username>, <password>, <endpoint>, and <database-name> with the values from Connection Details. In a connection URL, URL-encode any special characters in the password: for example, write @ as %40.

SSL is on for every new DBaaS instance. A DBaaS instance with SSL on requires SSL on every connection, on MySQL, MariaDB, and PostgreSQL. If SSL is off on an older DBaaS instance, turn it on first; see Enable SSL on a DBaaS instance. Once SSL is on, in the CA Certificate row under Connection Details, click Download to get the CA certificate, ca-cert.pem. Then point your client at it.

For MySQL and MariaDB, use the MySQL 8.0 client:

mysql -h <endpoint> -P 3306 -u <username> -p --ssl-mode=VERIFY_CA --ssl-ca=ca-cert.pem

PostgreSQL:

psql "host=<endpoint> port=5432 user=<username> dbname=<database-name> sslmode=verify-ca sslrootcert=ca-cert.pem"

<endpoint>, <username>, and <database-name> are the values from Connection Details. Both commands check the server against the CA certificate you downloaded. Keep that CA check, and leave the host-name check out; if a client reports a certificate error, see Troubleshooting DBaaS.

A successful connection shows the client’s prompt, and you are working in your database. If a connection times out or is refused, see Troubleshooting DBaaS.