Information for: DEVELOPERS   PARTNERS

Accessing your database from the command line

You can access the databases of your Acquia Cloud application using the drush ah-sql-cli command. The ah-sql-cli command is exactly like the drush sql-cli command, except that ah-sql-cli does not require a functioning Drupal website.

  1. Connect to an environment of your application using SSH. For more information, see Managing applications using the command line.

  2. Open a connection to your database with a command similar to the following:

    drush @[site].[env] ah-sql-cli
    

    You can also use the shorter alias, ah-sqlc.

    Replace [site] with your application name and [env] with the name of the environment whose database you want to connect to (typically, dev, test, or prod, for the Development, Staging, and Production environments, respectively). You can use the --db option to connect to a database other than your primary Drupal database. Note that unlike drush sql-cli, ah-sql-cli does not support the --uri option.

    For example:

    • If your site name is myexample and you want to connect to the primary database for your Production environment, use the following command:

      drush @myexample.prod ah-sql-cli
      
    • If your site name is myexample and you want to connect to the a secondary database named postal for your Staging environment, use a command similar to the following:

      drush @myexample.test ah-sql-cli --db=postal
      

You can now run SQL commands from the mysql> prompt. Enter quit to leave when you are done.

In addition to ah-sql-cli, Acquia Cloud includes another Drush command to connect to your database: ah-sql-connect. The ah-sql-connect command is exactly like the drush sql-connect command, except that ah-sql-connect does not require a functioning Drupal website. The ah-sql-connect command takes the same options as ah-sql-cli. The output of ah-sql-connect is the MySQL command, with user name, password, and database name, that you can use to connect directly to the database. For example:

drush @[site].[env] ah-sql-connect mysql -h free-1712 -u example1dev -pbfddVTKixQbn88i example1dev

For another approach, you can use phpMyAdmin, a GUI-based MySQL database management tool. For more information, see Tools for administering your database.

Command options

The drush ah-sql-cli and ah-sql-connect commands take the following options, in the format --option=value:

Option Description Value
--site The site name for the database to connect to. Use the drush @site.env alias instead of specifying this option directly.
--env The environment for the database to connect to. Use the drush @site.env alias instead of specifying this option directly.
--db The environment-agnostic database name. This is the name displayed on the Databases page for the environment in the Acquia Cloud interface. Defaults to the name of the default primary Drupal database for the website.

Note

When you run drush ah-sql-cli, Acquia Cloud may display the following message:

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

The -A option is a MySQL option and not a drush ah-sql-cli option. You should ignore it when you run drush ah-sql-cli.