---
title: "Working with databases"
date: "2024-02-14T06:18:38+00:00"
summary: "Learn how to manage, copy, and monitor databases for your Drupal application in Cloud Platform environments. Optimize performance and troubleshoot issues."
image:
type: "page"
url: "/acquia-cloud-platform/working-databases"
id: "a7bbaf82-3b35-4eac-a71c-7428dd4d8adc"
---

Table of contents will be added

Your Drupal application’s database contains the application’s content, configuration, and log information. When you import or create an application in Cloud Platform, you have several environments you can use to develop and manage your application, with each environment having its own database allowing your application to have several databases associated with it, depending on which environment you are working in.

You can use the Environments page in the Cloud Platform user interface to copy a database from one of your application’s environments to another by dragging the database between environments. You can use the **Application** > **Environments** page to add, back up, delete databases, or restore and delete database backups.

Adding a database
-----------------

Drupal sets up the application’s primary database when you install Drupal. Your application can also require more databases. You can create more databases by using the Cloud Platform user interface.

CD environments

You cannot create databases for [Cloud Platform CD environments](/acquia-cloud-platform/features/cd/env).

1.  [Sign in to the Cloud Platform user interface](/node/55875).
2.  Access your application, and click **Actions** > **Add Database**.
    
    Alternatively, access a specific environment in your application, and click **Databases** > **Add Database**.
    
3.  Enter the database name, and click **Add Database**. Adding a database creates unique databases for each environment and adds a block for the database on the **Databases** page.
    *   If the database is for a new website using Drupal multisite, enter the website name. Then, add the include statement from the **Databases** page to the `settings.php` file in the multisite directory (for example, `docroot/sites/[sitename]/settings.php`). For more information, see [About Drupal multisite installations](/acquia-cloud-platform/develop-apps/drupal-apps/multisite-installation).
    *   If the database is for added content for an existing application, enter a name (for example, for a postal code database, use “postalcodes”), and use `db_set_active('[Database]')` within Drupal to access it. Do not add the include statement from the **Databases** page to the `settings.php` file unless you intend the new database to be your application’s default Drupal database.

Note

*   Cloud Classic and Cloud Next support up to 100 databases. If you need to exceed beyond that limit, contact your Acquia account manager.
*   Database names can include a-z, A-Z, and 0-9. Database names must start with letters and cannot include only numbers. In addition, database names cannot include - (dash), \_ (underscore), and . (dot) characters.
*   The following are the limits for database connections in Cloud Next:
    *   250 connections in production environments
    *   25 connections in non-production environments

Configuring your application to use environment databases
---------------------------------------------------------

To view the include statement, which is also known as the [require statement](/acquia-cloud-platform/manage-apps/code/require-line)) for your database:

1.  [Sign in to the Cloud Platform user interface](/node/55875).
2.  Access a specific environment in your application, and click **Databases**.
3.  Select a specific database and click **PHP**.
    
    ![cloud-platform_database-include-statement.png](https://acquia.widen.net/content/9ee4c027-ef79-459c-b7f1-3e8652af9a2c/web/cloud-platform_database-include-statement.png?w=1090&itok=XZsNGxt3)
    

The include statement must be at the end of the `settings.php` file in your `/sites` directory, but it must be before any other Cloud Platform-specific entries in `settings.php`, including [Memcached configuration code](/acquia-cloud-platform/performance/memcached) or any code using [environment variables](/acquia-cloud-platform/using-environment-variables "Using environment variables").

The database include statement causes your application to use a unique database for each environment allowing you to use the same `settings.php` file in each of your Cloud Platform environments.

When you use the Cloud Platform user interface to install a Drupal distribution or import a website archive, or import an application using the Acquia Connector, Cloud Platform creates the database include statement in your `settings.php` file. Otherwise, you must edit the `settings.php` file to add the include statement. Do not add the include statement unless you intend the new database to be your application’s default Drupal database.

Copying a database across environments
--------------------------------------

As you develop your application, you may often want to update an environment with the version of the database from a different environment. Most commonly, you may want to update your Dev or Stage environment databases with the content and configuration from your Prod environment.

1.  [Sign in to the Cloud Platform user interface](/node/55875) and access your application.
2.  In the grid view, drag the source database container to the target environment you want to contain the database copy. For example, drag the Prod database to the Dev environment.
3.  If the application has more than one database, select the database you want to copy, or click **All** to select all the databases.
4.  Click **Continue**.
5.  Click **Copy** to confirm you want to overwrite the target environment’s database with the source environment’s database. The database migration begins, and the existing database is dropped (`drush sql-drop`) during the copy process.
    
    Important
    
    After your application is live, Acquia does not recommend copying a database into the Production environment. Doing so may lead to content loss on your application. While the database is copying, requests which cannot be served from cache will fail.
    
6.  You cannot copy a database to your Production environment when your application is in the Production mode. For more information, see [Using Production mode to protect your live application](/acquia-cloud-platform/manage-apps/prod-mode).

Viewing database information
----------------------------

To view information about your databases:

1.  [Sign in to the Cloud Platform user interface](/node/55875).
2.  Access a specific environment in your application and click **Databases**.
3.  Click the database for which you want to view detailed information.
4.  Click **Settings**.
    
    The system displays the connection information for the database.
    
    ![cloud-platform_database-details.png](https://acquia.widen.net/content/60ecbf85-9f59-4d9c-98b3-8565b3af4205/web/cloud-platform_database-details.png)
    

Cloud Platform displays the environment-agnostic database name at the top of the section, along with the following fields and their values:

*   **SSH Host**: Fully-qualified domain name needed to SSH in to the environment
*   **MySQL Host**: The hostname of the database infrastructure. It is only accessible after connecting to the SSH host.
*   **Name**: Environment-specific name for the database
*   **Username**: Username needed to connect to the database
*   **Password**: Password needed to connect to the database; click **Show** to reveal the password

Note

Cloud Platform API users must use the database machine name for any script options.

Backing up your database
------------------------

The Databases page displays the date and time of the last created backup for each database in each environment. You can also create on-demand backups and view, download, restore, and delete backups. For more information, see [Backing up your application](/acquia-cloud-platform/manage-apps/back-up). 

Deleting a database
-------------------

You can use the Databases page to delete a database, so long as it is not your Drupal application’s primary database. You cannot delete the primary database for your application. Doing so would prevent your application from working. Ensure that you exercise caution before deleting a database as all environments associated with the database are impacted.

Note

You cannot delete databases from [Cloud Platform CD environments](/acquia-cloud-platform/features/cd/env).

To delete a database:

1.  On the Databases page, locate the database that you want to delete and click **Delete**.

Monitoring and accessing your databases
---------------------------------------

Cloud Platform provides several tools you can use to monitor and access your application’s databases:

*   [Access the MySQL command line](/acquia-cloud-platform/manage-apps/database/cli). You have full grants on your application’s database, giving you complete control of the application’s database. The grants on your application’s database do not grant you access to the entire database system, nor do they grant you permission to add users or change permissions on the database system.
*   [Administer your database with a desktop application or phpMyAdmin](/acquia-cloud-platform/manage-apps/database/tools).
*   [View the slow query logs](/acquia-cloud-platform/monitor-apps/logs/slow-query).
*   Trace database queries using an application monitoring tool, such as [New Relic](/acquia-cloud-platform/monitor-apps/apm).

Troubleshooting database connection errors
------------------------------------------

You might run out of database connections for the schema. Typically, this occurs due to high traffic or inefficient queries for your application. This leads to greater concurrent connections. You can review your slow queries periodically to optimize your site. For more information, see [MySQL slow query logs](/acquia-cloud-platform/mysql-slow-query-logs "MySQL slow query logs").