All Products
Search
Document Center

PolarDB:Connect to a cluster

Last Updated:Dec 13, 2024

This topic describes how to use Data Management (DMS) or a MySQL client to connect to a PolarDB for MySQL cluster.

Prerequisites

Connect to a cluster

Use DMS to connect to a cluster

DMS is a visualized data management service provided by Alibaba Cloud. DMS provides various management services such as data management, schema management, access control, business intelligence (BI) charts, data trends, data tracking, performance optimization, and server management. You can use DMS to manage relational databases such as MySQL, SQL Server, and PostgreSQL databases and NoSQL databases such as MongoDB and Redis databases. You can also use DMS to manage Linux servers.

  1. Log on to the PolarDB console.
  2. In the upper-left corner of the console, select the region where the cluster resides.
  3. Find the cluster, and then click the cluster ID.
  4. In the upper-right corner of the Basic Information page, click Log on to Database.

  5. In the dialog box that appears, enter the Database Account and Database Password that you created for the PolarDB for MySQL cluster, and then click Login.登录页面

    Note

    The logon account must be granted management permissions on the database. Otherwise, you cannot find the database in the left-side navigation pane of the DMS console. For information about how to modify the permissions granted to an account, see Manage the password of a database account.

  6. After you log on to DMS, refresh the page. In the left-side navigation pane, click Instances Connected.

  7. In the Instances Connected list, click the cluster name, find the database, and then double-click the database name. Then, you can manage the database.

    1

Use a client to connect to a cluster

You can use a MySQL client to connect to a PolarDB cluster. The client used in the following example is HeidiSQL.

  1. Start HeidiSQL.

  2. In the lower-left corner of the session manager, click New.

  3. Specify the information about the PolarDB cluster to which you want to connect. The following table describes the parameters.

    Parameter

    Description

    Network type

    The network protocol type that is used to connect to the database. Select MariaDB or MySQL (TCP/IP).

    Hostname/IP address

    Enter a public or private endpoint of the PolarDB cluster.

    • If the client runs on an Elastic Compute Service (ECS) instance that is deployed in the same region and has the same network type as the PolarDB cluster, use a private endpoint. For example, if the ECS instance and the PolarDB cluster are deployed in a virtual private cloud (VPC) in the China (Hangzhou) region, you can use a private endpoint to establish a secure and fast connection.

    • In other scenarios, use a public endpoint.

    For more information about how to view the endpoint of a PolarDB cluster, see View the endpoint and port number.

    Username

    The name of the account that is used to connect to the PolarDB cluster.

    Password

    The password of the account.

    Port

    The port number in the public or private endpoint that is used to connect to the PolarDB cluster. The default port number is 3306.

  4. Click Open. If the connection information is valid, the client is connected to the cluster. HeidiSQL successfully connected to database

Use the CLI to connect to a cluster

If MySQL is installed on your server, you can run the following command in the CLI to connect to a PolarDB for MySQL cluster:

mysql -h<Endpoint> -P<Port> -u<Username> -p<Password>

Example:

mysql -hpc-bp1867z0z*****kjd.rwlb.rds.aliyuncs.com -P3306 -uroot12 -pPass*****33

Parameter

Description

Example

-h

The public or private endpoint of the PolarDB cluster. For more information about how to view the endpoint of a PolarDB cluster, see View the endpoint and port number.

pc-bpxxxxxxxxxxxxxx.mysql.polardb.rds.aliyuncs.com

-P

The port number that is used to connect to the PolarDB cluster.

  • If you use the private endpoint to connect to the PolarDB cluster, enter the private port number in the private endpoint.

  • If you use a public endpoint to connect to the PolarDB cluster, enter the port number in the public endpoint.

Note
  • The default port number is 3306.

  • If you want to use the default port, you do not need to specify a value for this parameter.

3306

-u

The name of the database account that you want to use to access the PolarDB cluster.

root

-p

The password for the database account.

Note

This parameter is required.

  • If you do not specify this parameter, you are required to enter the password again when the Enter password message is displayed.

  • If you specify this parameter, do not enter space characters between -p and the password.

Password233

FAQ

Why am I unable to connect an ECS instance to the internal endpoint of a PolarDB cluster?

To connect an ECS instance to the internal endpoint of a PolarDB cluster, the following requirements must be met:

  • The ECS instance and PolarDB cluster are deployed in the same region.

  • The ECS instance and PolarDB cluster use the same network type. If they use the VPC network type, they must be on the same VPC. If the ECS instance and PolarDB cluster are not on the same VPC, you can Use CEN and Basic Edition transit routers to connect VPCs in the same region.

  • The private IP address of the ECS instance is added to the whitelist of the PolarDB cluster.

If the PolarDB cluster is on a VPC while the ECS instance is on the classic network, you can use one of the following solutions to connect the ECS instance to the internal endpoint of the PolarDB cluster:

  • Solution 1: Migrate the ECS instance from the classic network to the VPC where the PolarDB cluster is deployed. For more information, see Migrate ECS instances from a classic network to a VPC.

    Note

    If the ECS instance also needs to access other resources on the classic network, do not migrate the ECS instance. Otherwise, the ECS instance cannot access the classic network.

  • Solution 2: Use the ClassicLink feature to connect the classic network to the VPC network.

Why am I unable to connect an ECS instance to the public endpoint of a PolarDB cluster?

You can perform the following steps:

  1. Check whether the endpoint, port, account, and password for the connection are correct. If yes, check whether the IP whitelist of the PolarDB cluster is correct.

  2. Add 0.0.0.0/0 to the IP whitelist of the PolarDB cluster. After the cluster is connected, execute the SHOW processlist statement to obtain the egress public IP address of the cluster. Add it to the whitelist of the cluster and delete 0.0.0.0/0 from the whitelist.

    Note

    0.0.0.0/0 in the IP whitelist indicates that all sources are allowed to access the cluster. Do not add 0.0.0.0/0 to the IP whitelist of the cluster unless it is necessary.

Why am I unable to connect an ECS instance to a PolarDB cluster?

An ECS instance can be connected to a PolarDB cluster over the internal network if the ECS instance and the PolarDB cluster belong to the same account and are on the same VPC in the same region. VPC isolation exists for different accounts or across different regions. See the following common reasons why an ECS instance cannot connect to a PolarDB cluster: