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

Database node CNAMEnode{node_id}-{environment_name}.{hoster_domain}
Private IP addressUse the internal address of the database node for connections inside the platform network.
Public IP addressUse only when a public IP address is attached to the database node.
!

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 TypeConnection 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

{node_id}The database container ID displayed in the dashboard.
{environment_name}The environment containing the database node.
{hoster_domain}The hosting-provider domain used by the environment.
{dbname}The database name.
user_nameThe database account username.
user_passwordThe database account password.
i

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 TypeConnection Code
MySQL / MariaDB
mysql_connect('HOST', 'USERNAME', 'PASSWORD');
PostgreSQL
pg_connect("host=host_address port=5432 dbname=postgres user=webadmin password=password");
i

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 localhost between 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

Connection to localhost failsReplace localhost with the database node CNAME, private IP, or attached public IP.
Hostname cannot be resolvedCheck the node ID, environment name, hosting-provider domain, and environment region.
Auto-cluster connection failsUse the ProxySQL endpoint instead of an individual database node.
PHP connection failsRemove the HTTP protocol prefix and verify the credentials.
Characters are stored incorrectlyAdd the UTF-8 parameters and confirm compatible database character encoding.

Related Guides

  • Database Hosting
  • Database Configuration Files
  • Database Auto-Configuration
  • MySQL Auto-Clustering
  • MariaDB Auto-Clustering