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

Prerequisites

You have created a privileged account or standard account for a database cluster. For more information, see Create database accounts.

Use DMS to connect to a cluster

DMS is a graphical data management service provided by Alibaba Cloud. It offers an integrated solution for data, server, and schema management, access security, BI charts, data trends, data tracking, and performance and optimization. DMS supports relational databases such as MySQL, SQL Server, and PostgreSQL, as well as non-relational databases such as MongoDB and Redis. DMS can also manage Linux servers.

  1. Find the target cluster and click the cluster ID. The Overview page appears.
  2. Click Log On to Database in the upper-right corner of the page.Overview
  3. On the database logon page, enter the endpoint and port number, and separate them with a colon (:). Enter the username and password of the privileged or standard account, and click Log On.Logon page
    Note DMS only supports logon to the primary endpoint but not the cluster endpoint. For more information about how to view the endpoint, see View endpoints.

Use a client to connect to a cluster

You can use a MySQL client to connect to a PolarDB MySQL cluster. In this topic, HeidiSQL is used.

  1. Start the HeidiSQL client.
  2. In the lower-left corner of the session manager, click New.Session manager
  3. Enter the information of the PolarDB cluster to be connected. The following table describes the parameters.
    Parameter Description
    Network type The network type of the database to be connected. Select MariaDB or MySQL (TCP/IP).
    Hostname/IP Enter the public or internal endpoint of the cluster.
    • If your client is deployed in an ECS instance, and the instance is in the same region and has the same network type as the destination cluster, you can use the internal endpoint. For example, the ECS instance and PolarDB cluster are both in the same VPC located in the China (Hangzhou) region. You can use the internal endpoint to establish a secure connection.
    • Use the public endpoint for other situations.
    To view the endpoint and port information of the PolarDB cluster, perform the following steps:
    1. Log on to the ApsaraDB for PolarDB console.
    2. In the upper-left corner of the page, select the region where the cluster is located.
    3. Find the target cluster and click the cluster ID.
    4. You can view the endpoint and port information on the Overview page.
    User The account that is used to connect to the PolarDB cluster.
    Password The password of the account.
    Port Enter the corresponding port of the public or internal endpoint.
  4. Click Open. If the connection information is correct, you can connect to the PolarDB cluster.HeidiSQL connects to the database

Use the command line to connect to a cluster

If MySQL is installed on your server, you can connect to a PolarDB MySQL cluster by running the following command in the command line:

mysql -h<Endpoint> -P<Port> -u<Username> -p<Password> -D<Database>
Parameter Description Example
-h The public or internal endpoint of the PolarDB MySQL cluster. For more information, see View endpoints. pc-bpxxxxxxxxxxxxxx.mysql.polardb.rds.aliyuncs.com
-P The port of the PolarDB MySQL cluster.
  • If you establish a connection to the internal endpoint, you must enter the internal port of the PolarDB MySQL cluster.
  • If you establish a connection to the public endpoint, you must enter the public port of the PolarDB MySQL cluster.
Note
  • The default port is 3306.
  • If the port that you use is the default port, this parameter can be left empty.
3306
-u The account that is used to connect to the PolarDB cluster. root
-p The password of the account.
Note This parameter is optional.
  • If you do not specify this parameter, you must enter the password later.
  • When you specify this parameter, no space is required between -p and the database password.
password233
-D The name of the database to connect to.
Note
  • This parameter is optional.
  • You can enter only the database name and leave out -D.
mysql

Troubleshoot connection failures

  • The IP address whitelist is incorrectly configured.
    • The default whitelist contains only the IP address 127.0.0.1. 127.0.0.1 indicates that no IP address is allowed to access the PolarDB cluster. Therefore, you must add IP addresses to the whitelist. For more information, see Configure the IP address whitelist for a cluster.
    • The IP address in the whitelist is set to 0.0.0.0, while the correct format is 0.0.0.0/0.
      Note 0.0.0.0/0 indicates that all IP addresses are allowed to access the PolarDB cluster. Proceed with caution when you add this CIDR block to the whitelist.
    • The public IP address that you add to the whitelist may not be the real egress IP address. For example, the public IP address may be a dynamic IP address. The tools or websites used to query the public IP addresses provide the incorrect IP addresses.
  • The internal or public endpoint is incorrectly used.

    The connection fails when you use an internal endpoint to connect over the Internet or use a public endpoint to connect over the internal network.

    Use the endpoint as needed. If you want to connect to the PolarDB cluster over the internal network, you must use the internal endpoint. If you need to connect to the cluster over the Internet, you must use the public endpoint.

  • The network types of the ECS instance and the PolarDB cluster are different. The ECS instance is in the classic network while the PolarDB cluster is in a VPC.
    • Solution 1 (recommended): Migrate the ECS instance to the same VPC.
      Note The ECS instance and the PolarDB cluster must be in the same VPC to communicate over the internal network.
    • Solution 2: Use the ClassicLink feature to establish an internal network connection between the ECS instance in the classic network and the PolarDB cluster in the VPC.
    • Solution 3: Connect the ECS instance to the PolarDB cluster over the Internet by using the public endpoint of the cluster. This solution has the lowest security, stability, and performance.