A global database network (GDN) spans multiple PolarDB clusters deployed across different regions. Use the GDN's global domain name to maintain a stable connection string that routes to the nearest cluster and stays unchanged after a primary cluster switchover — no application reconfiguration required.
This topic explains how routing works in a GDN, which endpoint to use for your workload, and how to connect using the console, a client, the CLI, or application code.
How routing works
Request routing in a GDN is controlled by the database proxy configuration of each cluster. Connect to the nearest cluster endpoint, and the proxy routes each request automatically:
Writes (all DML, DDL, requests inside transactions) go to the primary node of the primary cluster.
Reads outside transactions go to read-only nodes of the local secondary cluster by default, providing the lowest latency.
If session consistency is enabled, some reads are redirected to the primary cluster to guarantee data freshness.
The primary node of a secondary cluster handles asynchronous data replication from the primary cluster only — it does not serve read or write requests. In the routing table below, "primary node" refers to the primary node of the primary cluster, and "read-only nodes" refers to the read-only nodes of the secondary clusters.
Detailed routing rules
| Destination | Requests routed there |
|---|---|
| Primary node of the primary cluster (always) | All DML: INSERT, UPDATE, DELETE, SELECT FOR UPDATE |
| All DDL (create, delete, or alter tables or databases; manage permissions) | |
| All requests inside transactions | |
| User-defined functions | |
| Stored procedures | |
EXECUTE statements | |
| Multi Statements | |
| Requests using temporary tables | |
SELECT last_insert_id() | |
| All queries and modifications to user variables | |
SHOW PROCESSLIST | |
KILL (statement, not the command) | |
| Read-only nodes or primary node | Read requests outside transactions |
COM_STMT_EXECUTE commands | |
| All nodes | All modifications to system variables |
USE commands | |
COM_STMT_PREPARE commands | |
COM_CHANGE_USER, COM_QUIT, COM_SET_OPTION commands |
Reads are sent to the primary node only when Primary Node Accepts Read Requests is set to Yes in the database proxy configuration.
Choose an endpoint
Select your endpoint based on your workload:
| Goal | Recommended endpoint |
|---|---|
| Read/write from the closest region | Cluster endpoint or custom endpoint with Read/Write Mode set to Read/Write (Automatic Read/Write Splitting) on the nearest secondary cluster |
| Writes only, or strict read-after-write consistency | Primary cluster endpoint |
| Reads only, tolerates replication lag | Custom endpoint on a secondary cluster with Primary Node Accepts Read Requests set to No and Consistency Level set to Eventual Consistency (Weak) |
The Primary Endpoint and custom endpoints with Read/Write Mode set to Read-only do not support GDN read/write splitting.
Global domain name
The GDN global domain name routes requests to the nearest cluster and preserves the same connection string after a primary cluster switchover. Use it to avoid updating application configuration after failover.
Prerequisites
Before you begin, ensure that you have:
A GDN with at least one secondary cluster
A database account and password for the target cluster
(For application connections) Network access from your application host to the cluster endpoint in the target region
View cluster endpoints
Log on to the PolarDB console and click Global Database Network (GDN) in the navigation pane.
On the Global Database Network (GDN) page, find the target GDN and click its Global Database Network ID.
In the Clusters section, find the target secondary cluster and click View in the Cluster Endpoint column. The dialog box shows the Private and Public endpoints of the default cluster endpoint.

To see all endpoints for a cluster, click Visit the Overview page of the cluster. The Database Connections section on the cluster's details page lists every available endpoint.
Connect to a GDN cluster
The following sections cover four connection methods. Use whichever fits your workflow.
Use DMS
Data Management Service (DMS) is a browser-based database management tool built into the Alibaba Cloud console. It lets you query, manage, and monitor PolarDB clusters without installing any client software.
Log on to the PolarDB console and click Clusters in the navigation pane. Select the target region, then click the cluster ID to open the Basic Information page.
In the upper-right corner, click Log on to Database.

Enter the Database Account and Database Password, then click Login.

After logging in, click Instances Connected in the navigation pane to view and manage the cluster.

Use a MySQL client
The following steps use MySQL Workbench 8.0.29. Other MySQL-compatible clients follow the same pattern.
Download and install MySQL Workbench.
Open MySQL Workbench and choose Database > Connect to Database.
Enter the connection details and click OK.
Parameter Description Example Hostname The cluster endpoint. See Database connection. pc-2***.rwlb.rds.aliyuncs.comPort The port for the endpoint. Default: 3306.3306Username The database account. See Create a database account. polardb_mysql_userPassword The database account password. Pass***233
Use the CLI
If the MySQL client is installed on your server, run the following command:
mysql -h <Endpoint> -P <Port> -u <Account> -p<Password>Example:
mysql -h pc-2***.rwlb.rds.aliyuncs.com -P3306 -upolardb_mysql_user -pPass***233| Parameter | Description | Example |
|---|---|---|
-h | The cluster endpoint. See Database connection. | pc-2***.rwlb.rds.aliyuncs.com |
-P | The port for the endpoint. Default: 3306. Omit this parameter to use the default. | 3306 |
-u | The database account. See Create a database account. | polardb_mysql_user |
-p | The database account password. Required. Do not add a space between -p and the password. Omit the value to enter it interactively when Enter password: appears. | Pass***233 |
Use application code
PolarDB for MySQL is wire-compatible with MySQL. Replace the endpoint, port, account, and password in any MySQL driver or ORM — no other code changes are needed.
Java
This example uses a Maven project with the MySQL JDBC driver (version 8.0.27).
Step 1: Add the driver dependency to pom.xml:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.27</version>
</dependency>Step 2: Connect to the cluster. Replace <HOST>, <USER>, <PASSWORD>, <DATABASE>, <YOUR_TABLE_NAME>, and <YOUR_TABLE_COLUMN_NAME> with your values.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class DatabaseConnection {
public static void main(String[] args) {
// Endpoint, port, and database name of the PolarDB cluster
String url = "jdbc:mysql://<HOST>:3306/<DATABASE>?useSSL=false&serverTimezone=UTC";
// Database account
String user = "<USER>";
// Database account password
String password = "<PASSWORD>";
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection conn = DriverManager.getConnection(url, user, password);
Statement stmt = conn.createStatement();
// Table to query
ResultSet rs = stmt.executeQuery("SELECT * FROM `<YOUR_TABLE_NAME>`");
while (rs.next()) {
// Column to print
System.out.println(rs.getString("<YOUR_TABLE_COLUMN_NAME>"));
}
rs.close();
stmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}Python
This example uses Python 3 with the PyMySQL library.
Step 1: Install PyMySQL:
pip3 install PyMySQLStep 2: Connect to the cluster. Replace <HOST>, <USER>, <PASSWORD>, <DATABASE>, and <YOUR_TABLE_NAME> with your values.
import pymysql
host = '<HOST>' # Cluster endpoint
port = 3306 # Default port
user = '<USER>' # Database account
password = '<PASSWORD>' # Database account password
database = '<DATABASE>' # Database name
try:
connection = pymysql.connect(
host=host,
port=port,
user=user,
passwd=password,
db=database
)
with connection.cursor() as cursor:
sql = "SELECT * FROM '<YOUR_TABLE_NAME>'"
cursor.execute(sql)
results = cursor.fetchall()
for row in results:
print(row)
finally:
if 'connection' in locals() and connection.open:
connection.close()Go
This example uses Go 1.23.0 with the database/sql package and go-sql-driver/mysql driver.
Step 1: Install the driver:
go get -u github.com/go-sql-driver/mysqlStep 2: Connect to the cluster. Replace <HOST>, <USER>, <PASSWORD>, <DATABASE>, and <YOUR_TABLE_NAME> with your values.
package main
import (
"database/sql"
"fmt"
"log"
_ "github.com/go-sql-driver/mysql"
)
func main() {
dbHost := "<HOST>" // Cluster endpoint
dbPort := "3306" // Default port
dbUser := "<USER>" // Database account
dbPass := "<PASSWORD>" // Database account password
dbName := "<DATABASE>" // Database name
// Build the DSN (Data Source Name)
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Local",
dbUser, dbPass, dbHost, dbPort, dbName)
db, err := sql.Open("mysql", dsn)
if err != nil {
log.Fatalf("Failed to open connection: %v", err)
}
defer db.Close()
// Verify the connection
if err = db.Ping(); err != nil {
log.Fatalf("Failed to connect: %v", err)
}
// Print the server version
var version string
if err = db.QueryRow("SELECT VERSION()").Scan(&version); err != nil {
log.Fatalf("Failed to query version: %v", err)
}
fmt.Printf("Connected. Server version: %s\n", version)
// Run a query
rows, err := db.Query("SELECT * FROM '<YOUR_TABLE_NAME>'")
if err != nil {
log.Fatalf("Failed to execute query: %v", err)
}
defer rows.Close()
}What's next
Global Database Network (GDN) — GDN architecture and common use cases.
Create a global domain name — Set up a stable connection address that survives primary cluster switchovers.
API reference
| API | Description |
|---|---|
| DescribeDBClusterEndpoints | Queries the endpoint information of a PolarDB cluster. |
| ModifyDBClusterEndpoint | Modifies cluster endpoint attributes: read/write mode, auto-add new nodes, consistency level, transaction splitting, primary node read acceptance, and connection pool settings. |