Access MariaDB and MySQL Databases
Configure your MariaDB or MySQL database connections on Pantheon.
This section provides information on how to access your MariaDB or MySQL database through Pantheon.
Due to the nature of our platform, the connection information will change from time to time due to server upgrades, endpoint migrations, etc. You will need to check the Dashboard periodically or when you can’t connect.
Database Connection Information
Platform Considerations
Connections will change from time to time due to the containerized nature of the platform. For security reasons, using the $_ENV superglobal inside PHP applications is not supported. As an alternative, consider using a Bash script and Terminus connection. You can view an example in the Create Secure Connection to MySQL using TLS documentation.
Access Your Database Directly
You cannot access the database directly if you have purchased Secure Runtime Access.
The database credentials for each site environment are located in your Site Dashboard.
Navigate to the environment you want to connect with, and select Connection Info to view your Database credentials.
The following required fields are provided:
- Server: The hostname of the server.
- Port: The TCP/IP port number to use for the connection. The platform randomly selects the port number. Port numbers will differ in every environment for each site, and might not match what PHP reports.
- Username: The user name to use when connecting to server.
- Password: The password to use when connecting to the server.
- Database: The database name to use. This value will always be
pantheonand cannot be altered.
Each database server is in the cloud, which allows credentials to occasionally be updated, without any notice. Normally, this is transparent to a site, as the credentials are automatically included by the server. However, if you've saved the credentials in a local client and a month later you can't connect, check your Dashboard for the current credentials.
There's a wide array of MySQL clients that you can use, including:
Refer to the documentation or issue queue of your software to learn more about how to configure a connection.
See our platform considerations for phpMyAdmin usage.
Open Sequel Ace Database Connection
Drupal users can create spf-template.spf and use the following script to establish a database connection in Sequel Ace via Terminus and Drush:
Props to Aaron Bauman for writing this script!
Accessing the Database via Your Application with PHP
You can connect to the application with Pantheon's internal network. Use the following variables in your application to access the database:
- DB_HOST: Name of the server.
- DB_PORT: Database port used.
- DB_USER: User name to use when connecting to server.
- DB_PASSWORD: The password to use when connecting to the server.
- DB_NAME: The database name to use. This value will always be
pantheonand cannot be altered. - REPLICA_DB_HOST: Database IP address. This will be changing to have the same value as DB_HOST, and route to a proxy server. We will no longer support connections via IP Address.
- REPLICA_DB_PORT: Replica database port.
- REPLICA_DB_USER: MySQL replica user name to use when connecting to server.
- REPLICA_DB_PASSWORD: The password to use when connecting to the server.
- REPLICA_DB_NAME: The replica database name to use. This value will always be
pantheonand cannot be altered.
For example:
SSH Tunneling
MySQL connections made to Pantheon are encrypted by default:
Developers can use SSH tunnels to add additional layers of encryption to remote MySQL connections, or tunnel the connection across non-standard ports. For more information on how to set up tunnels for databases, refer to Secure Connections to Pantheon Services via TLS or SSH Tunnels.
Troubleshooting MySQL Connections
Lost Connection to MySQL Server
Or
This error occurs when a request is sent to a database server that is in sleep mode. Pantheon containers spin down after about one hour of idle time. Live environments on a paid plan spin down after 12 hours of idle time. Environments usually spin up within 30 seconds of receiving a request. To resolve this error, wake environments by loading the home page or with the following Terminus command:
Can't Connect to Local MySQL Server Through Socket
Refer to Database Connection Errors to troubleshoot connection errors such as the following:
