This page covers the application-side connection details for MySQL, MariaDB, and Percona on Stack Harbor PaaS. The three engines are wire-compatible, so most drivers work against any of them with the same connection string — the differences are mostly in the recommended driver and the URL prefix.
For the host options (CNAME, private IP, public IP), the UTF-8 encoding parameters, and the clustered-topology ProxySQL endpoint, see Database connection strings first. This page focuses on the per-language driver code.
Java (JDBC)
For a single-node database, use the MySQL Connector/J driver:
String URL = "jdbc:mysql://node{node_id}-{environment_name}.{domain}/{dbname}";
Connection conn = DriverManager.getConnection(URL, user, password);
For a MySQL or Percona auto-cluster, point at the ProxySQL endpoint:
String URL = "jdbc:mysql://proxy.{environment_name}.{domain}:3306/{dbname}";
Connection conn = DriverManager.getConnection(URL, user, password);
For a MariaDB auto-cluster, use the MariaDB driver and disable pipeline auth (ProxySQL does not implement it):
String URL = "jdbc:mariadb://proxy.{environment_name}.{domain}:3306/{dbname}?usePipelineAuth=false";
Connection conn = DriverManager.getConnection(URL, user, password);
Use a connection-pool library (HikariCP, c3p0) in production rather than opening a fresh connection per query.
PHP
PDO with the MySQL driver:
$pdo = new PDO(
'mysql:host=node{node_id}-{environment_name}.{domain};dbname={dbname};charset=utf8mb4',
$user,
$password
);
Or the procedural mysqli:
$conn = mysqli_connect('node{node_id}-{environment_name}.{domain}', $user, $password, $dbname);
mysqli_set_charset($conn, 'utf8mb4');
Pick utf8mb4 over utf8 — the latter is a MySQL alias for 3-byte UTF-8 and does not support 4-byte code points (emoji, some CJK characters).
Python
For MySQL and Percona, the mysql-connector-python driver:
import mysql.connector
conn = mysql.connector.connect(
host='node{node_id}-{environment_name}.{domain}',
user=user,
password=password,
database=dbname,
)
For MariaDB, the official MariaDB Connector/Python is the recommended driver. The interface is dbapi-compatible:
import mariadb
conn = mariadb.connect(
host='node{node_id}-{environment_name}.{domain}',
user=user,
password=password,
database=dbname,
)
Both connect against the ProxySQL endpoint as well, for clustered topologies.
Node.js
The mysql2 driver (the recommended one for current Node.js):
import mysql from 'mysql2/promise';
const conn = await mysql.createConnection({
host: 'node{node_id}-{environment_name}.{domain}',
user,
password,
database: dbname,
});
For pooled connections, use mysql.createPool instead — the mysql2 pool reuses connections and handles reconnects.
Notes
- No
localhost. Application and database are on separate containers. The loopback is not the database. - Email credentials. The platform sends root credentials by email when the container is created. Create application users at lesser privilege from the admin panel (phpMyAdmin) instead of using root from the application.
- TLS in transit. For environments where TLS between the application and the database is required, install the Encryption in Transit add-on. The driver will then need the appropriate
useSSL(Java),sslmode/ssl(PHP / Python), orssl(Node.js) option.
See also
- Database connection strings — host options, UTF-8 encoding, clustered ProxySQL endpoint.
- MySQL high availability — clustered topologies behind ProxySQL.
- MySQL/MariaDB/Percona — engine-level reference.