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

Prerequisites

A privileged account or standard account is created for a PolarDB for MySQL cluster. For more information, see Create a database account.

Use DMS to connect to a PolarDB for MySQL cluster

DMS is a visualized data management service provided by Alibaba Cloud. It provides various management services, such as data management, schema management, access control, BI charts, data trends, data tracking, performance optimization, and server management. DMS supports relational databases such as MySQL, SQL Server, and PostgreSQL, as well as NoSQL databases such as MongoDB and Redis. DMS also supports the management of 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 Overview page, click Log On to Database.Overview
  5. In the dialog box that appears, specify Database Account and Database Password that are created in the PolarDB for MySQL cluster, and click Login.Logon page
    Note The account that is used to log on must have the permissions on the specified database. Otherwise, you cannot find the specified database in the left-side navigation pane of the DMS console. For more information about how to modify the permissions of a database account, see Modify the permissions of a standard account.
  6. After you log on to DMS, refresh the page. In the left-side navigation pane, click Logged in instance.
  7. On the Logged in instance page, click the cluster name and double-click the database name. Then, you can manage the database.
    1

Use a client to connect to a PolarDB for MySQL cluster

You can use a MySQL client to connect a PolarDB 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. Select MariaDB or MySQL (TCP/IP).
    Hostname/IP Enter the public or internal 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 the internal endpoint. For example, if the ECS instance and PolarDB cluster are deployed in a virtual private cloud (VPC) in the China (Hangzhou) region, you can use the internal endpoint to establish a secure and fast connection.
    • Use the public endpoint for other scenarios.
    To view the endpoint and port information of the PolarDB cluster, perform the following steps:
    1. Log on to the PolarDB console.
    2. In the upper-left corner of the page, select the region where the cluster that you want to manage is deployed.
    3. Find the 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 The port number of the public or internal endpoint for the PolarDB cluster. The default port number is 3306.
  4. Click Open. If the connection information is valid, you can connect to the cluster.HeidiSQL connects to the database

Use the command-line interface (CLI) to connect to a PolarDB for MySQL cluster

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

mysql -h<Endpoint> -P<Port> -u<Username> -p<Password> -D<Database>
Parameter Description Example
-h The public or internal endpoint of the PolarDB cluster. For more information, see View or apply for an endpoint. pc-bpxxxxxxxxxxxxxx.mysql.polardb.rds.aliyuncs.com
-P The port number of the PolarDB cluster.
  • If you use the internal endpoint, you must enter the internal port number of the PolarDB cluster.
  • If you use the public endpoint, you must enter the public port number of the PolarDB cluster.
Note
  • The default port number is 3306.
  • If you use the default port, you do not need to specify this parameter.
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 are required to enter the password when you connect to the cluster.
  • If you specify this parameter, do not enter a space character between -p and the password.
Password233
-D The name of the database to which you want to connect.
Note
  • This parameter is optional.
  • You can enter only the database name and exclude -D.
mysql

Troubleshooting

  • The IP address whitelist is error.
    • 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 a whitelist for a cluster.
    • The whitelist is set to 0.0.0.0. The valid format is 0.0.0.0/0.
      Notice 0.0.0.0/0 indicates that all IP addresses are allowed to access the PolarDB cluster
    • The public IP addresses that you add to the whitelist are invalid. For example, the public IP address may be a dynamic IP address. The tools or websites that are used to query the public IP addresses provide invalid IP addresses.
  • The wrong internal or public endpoint is used.

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

    Use the required endpoint. If you want to connect to the PolarDB cluster through an internal network, you must use the internal endpoint of the PolarDB cluster. If you want to connect to the PolarDB cluster over the Internet, you must use the public endpoint of the PolarDB cluster.

  • The network types of the ECS instance and the PolarDB cluster are different. The ECS instance is deployed in the classic network while the PolarDB cluster is deployed in a VPC.
    • Solution 1 (recommended): Migrate the ECS instance to the same VPC. For more information, see Migrate ECS instances.
      Note The ECS instance and the PolarDB cluster must be deployed in the same VPC to communicate with each other through 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 provides the lowest security, stability, and performance.