Database Connection Strings
Database Connection Strings
Every application server and database created on the platform runs in a separate container. To connect an application to a database, configure a connection string using the database node CNAME, private IP address, or attached public IP address.
Database Host Options
node{node_id}-{environment_name}.{hoster_domain}Do not use localhost
The application and database run in separate containers. Therefore, localhost points to the application container itself and cannot be used to connect to the database container.
Database Connection for Java Applications
| Database Type | Connection Code |
|---|---|
| MySQL / MariaDB | String URL = "jdbc:mysql://node{node_id}-{environment_name}.{hoster_domain}/{dbname}";
DriverManager.getConnection(URL, user_name, user_password); |
| MySQL Auto-Cluster | Connect through the highly available ProxySQL load balancers. String URL = "jdbc:mysql://proxy.{environment_name}.{hoster_domain}:3306/{dbname}";
DriverManager.getConnection(URL, user_name, user_password); |
| MariaDB Auto-Cluster | Connect through the highly available ProxySQL load balancers. String URL = "jdbc:mariadb://proxy.{environment_name}.{hoster_domain}:3306/{dbname}?usePipelineAuth=false";
DriverManager.getConnection(URL, user_name, user_password); |
| PostgreSQL | String URL = "jdbc:postgresql://node{node_id}-{environment_name}.{hoster_domain}/{dbname}";
DriverManager.getConnection(URL, user_name, user_password); |
Connection String Parameters
Environment regions
When multiple environment regions are available, the {hoster_domain} value can differ from the platform’s general domain.
UTF-8 Encoding
Add the Unicode and character-encoding parameters to a Java connection string:
jdbc:{dbtype}://node{node_id}-{environment_name}.{hoster_domain}/{dbname}?useUnicode=yes&characterEncoding=UTF-8
Database Connection for PHP Applications
| Database Type | Connection Code |
|---|---|
| MySQL / MariaDB | mysql_connect('HOST', 'USERNAME', 'PASSWORD'); |
| PostgreSQL | pg_connect("host=host_address port=5432 dbname=postgres user=webadmin password=password"); |
Host format
Enter the database host without http:// or https://. The database is not accessed through an HTTP URL.
Connection credentials
The database address and credentials are provided in the email sent after the database server is created.
Expected Result
The application connects to the selected database through the node CNAME, private IP, public IP, or the ProxySQL endpoint used by an auto-clustered MySQL or MariaDB topology.
Important Notes
- Do not use
localhostbetween separate application and database containers. - Use the database node CNAME or private IP for internal connections.
- A public IP can be used only when attached to the database node.
- Use the ProxySQL hostname for MySQL or MariaDB Auto-Cluster connections.
- Do not include an HTTP protocol prefix in the database host.
- Check the environment-specific domain when multiple regions are available.
Common Issues and Solutions
localhost with the database node CNAME, private IP, or attached public IP.Related Guides
- Database Hosting
- Database Configuration Files
- Database Auto-Configuration
- MySQL Auto-Clustering
- MariaDB Auto-Clustering
