Sharing a database between stacks

There are a number of reasons why you might want to share a database between your stacks. For example, you can test UI changes with your users while still using production data.

It is not a good idea to share your database between stacks in certain scenarios (eg. for a reporting tool) - instead we recommend that you use database replication to use a master/slave setup.

Your first stack will be deployed as normal, with a database managed by Cloud 66. Your second stack will be deployed with an external database (as it will use the first stacks database).


Ensure that you do not select the option for db:schema:load during the build of your second stack, as this could destroy the data on the first stack.

Firstly, you need to open your firewall on the first stack to allow your second stacks web servers to access the database.

You will then reference the database credentials from your first stack in the database.yml of your second stack. You can reference the environment variables for these credentials on your first stack like so (your stack UID is available on your Stack information page):


For example, your environment variables would be set like this:


Database credentials such as username and password are not available for cross-stack referencing for security reasons. Instead, copy and paste them across as environment variables. Your database.yml would look something like this:

host: <%= ENV['MYSQL_ADDRESS'] %>
username: <%= ENV['MYSQL_USERNAME'] %>
password: <%= ENV['MYSQL_PASSWORD'] %>
database: <%= ENV['MYSQL_DATABASE'] %>

Still need help? Contact Us Contact Us