All the information you need to connect to a MySQL for Compose deployment.
If you want to use a particular language, you can go directly to its dedicated page:
The connection string is your first point of reference when connecting to Compose for MySQL; it contains almost all the information you need to connect to a database. You can find your connection strings in the deployment’s Connection Info panel.
The Connection Info panel.
To use it you need to enter the username and password into the
[password] positions respectively. If you want to use the 'admin' user's password, you can find it by revealing the password in the Credentials section of Connection Info.
[password] are then automatically replaced with your credentials in the displayed connection string.
The examples in this guide connect with the admin user account.
The admin user is a fully privileged user who has administrative access to all your databases. However, for security reasons, you may want to create users and specify their permissions. More information can be found on the User Management for Compose for MySQL page.
The connection string is formatted as a URI that can be used where drivers and applications understand the standardized format. Other applications can extract the essential details from the connection string URI.
Other drivers use component parts of the connection URI – the host name and port – for their connection parameters. The host name is found after the
@ symbol and the port number is after the
:. They are marked in the following screenshot:
Diagram of a connection string.
Every Compose deployment automatically has a database with the name "compose" created in it to ensure at least one database exists and can be connected to with the default connection string.
If you don't designate a database to connect to, you need the
USE my_database command to select a database; a MySQL connection doesn't have to specify a database to connect.
All MySQL deployments have SSL enabled by default; however, the way MySQL does SSL means it will also accept non-SSL connections. This means that, when configuring your application's MySQL driver, you need to ensure that it creates a secure connection. With the MySQL command line, you can do this by adding
--ssl-mode=REQUIRED to the connection command. For application drivers, the settings are specific to the driver. In the examples we will show commands that should always and only connect with SSL enabled.
Compose deployments offer a self-signed certificate, which can be used to validate the host being talked to.
To use the self-signed certificate, copy it to a file. The certificate is found on the Deployment Overview page. Click the Show certificate button. Then enter your Compose account password to view the certificate:
Example of the expanded self-signed certificate.
Copy and paste the text from
-----BEGIN CERTIFICATE----- to
-----END CERTIFICATE----- into a file with the extension
.pem, depending on which the connection driver requires. Save the file to a location that you can access because we'll need the certificate's path later.
To directly connect to and administrate your Compose for MySQL deployment, you may use the command line. To do so, you have to install MySQL on your local machine. Each platform has its own installation packages, so choose the one that works best for you. You can find Oracle community packages at http://dev.mysql.com/downloads/. Before you download from there, be aware that on Linux you will usually find MySQL in your distributions repository. If you're using a Mac, you can install MySQL with Homebrew, which compiles and installs the latest version.
To access your deployment via the terminal, copy and paste the command line string provided in the Connection info panel into your terminal to connect to your deployment.
mysql -u [username] -p --host aws-us-east-1-portal.5.dblayer.com --port 16967 --ssl-mode=REQUIRED
To enable SSL when connecting, use
--ssl-mode=REQUIRED. The default user is named "admin" which you use as the username in the
-u parameter. After running the command, you'll be prompted to enter the admin user's password, which you can get from the credentials section of the Connection info panel.
Compose for MySQL has SSL enabled by default, but when connecting, you should take extra precautions by using the
--ssl-mode=REQUIRED option on the command line. This stops MySQL falling back, for whatever reason, to an unencrypted connection.
If you prefer, you can use the self-signed certificate to verify. Change the
--ssl-mode parameter to
--ssl-mode=VERIFY_CA and add
--ssl-ca with the path and name of your .pem file:
mysql -u [username] -p --host aws-us-east-1-portal.5.dblayer.com --port 16967 --ssl-mode=VERIFY_CA --ssl-ca=<your_file>.pem
If this article didn't solve things, summon a human and get some help!