Adding a database to your application


Cloud 66 natively supports the following databases and datastores:

  • MySQL
  • PostgreSQL
  • Redis
  • MongoDB
  • InfluxDB

You can also use other databases

It's perfectly feasible to manually install and use other database engines or datastores as part of your Cloud 66 application. We've simply automated management of the engines listed above because they are the most popular choices.

There are two main routes to add a database to a Cloud 66 application:

  1. As part of the initial build and deploy process
  2. After the app has already been deployed

This guide deals with the second of these cases. For the first, please consult our Getting Started guide.

What you'll need

Before you start, please check you have the following:

  • A Cloud 66 Account — If you don't already have one, sign up for a Cloud 66 account. You'll get free unlimited access to all products for 4 weeks.
  • An existing application set up in Cloud 66 — To make the most of this tutorial you need to have an app already set up in Cloud 66. Follow our Getting Started guide if you're not sure how to do this.

Adding a database to an existing app

Let's assume that your application was previously completely stateless, but now requires a data layer. As such you've decided to add a traditional relational database and have chosen to use MySQL.

There are two ways to add a database to an existing app:

  1. Via the Cloud 66 Dashboard
  2. Building a new completely new version of the app, and adding the database during the build process.

Immutability is your friend

Although option 2 might seem extreme, it follows the principle of "immutability". It is always more reliable and more manageable to deploy an updated application as though it were new, rather than trying to patch an existing flawed setup.

Configure a database via the Dashboard

To add MySQL to your application:

You can now watch the logs, as usual to see the progress of the process.

Testing your new database

Once MySQL has been deployed, you can test it by logging directly into the server on which it is running via SSH. Cloud 66 Toolbelt is the quickest way to do this.

When you are connected to your MySQL server you can run the following command to check it is running properly: /etc/init.d/mysql status - this will give you a brief status report on the state of MySQL.

You can also use this opportunity to log into your database. You can find the username and password for MySQL by clicking on the name of the server on the Server Overview page. The login details are available on the next page.

To log in use the following command format: mysql -u*username* -p*yourpassword* replacing the values with your own username and password. Note that there are no spaces after the -u and -p commands.

You now have a fully functional MySQL database running as part of your application.

Zero-downtime deployments