This topic describes how to use Data Management (DMS) or a MySQL client to connect to an ApsaraDB PolarDB MySQL-compatible edition cluster.

Prerequisites

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

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 Overview page, click Log On to Database. Overview
  5. In the dialog box that appears, enter the database account and database password that you created for the PolarDB for MySQL cluster and click Login. Logon page
    Note The account that is used to log on must have management permissions on the database that you want to manage. Otherwise, you cannot find the database in the left-side navigation pane of the DMS console. For more information about how to modify the permissions granted to an 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 Instances Connected.
  7. In the Instances Connected list, click the cluster name, find the database, and then double-click the database name.
    1

Use a client to connect to a cluster

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

  1. Start HeidiSQL.
  2. In the lower-left corner of the session manager, click New. Session manager
  3. Specify the information of the PolarDB cluster 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 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.
    • Use a public endpoint for other scenarios.
    To view the endpoint and port information about 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 is deployed.
    3. Find the cluster and click the cluster ID.
    4. On the Overview page, view the endpoint and port information.
    User The name of 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 private endpoint for 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 is connected to the 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 ApsaraDB PolarDB MySQL-compatible edition cluster:

mysql -h<Endpoint> -P<Port> -u<Username> -p<Password> -D<Database>
Parameter Description Example
-h The public or private endpoint of the PolarDB cluster. For more information about endpoints, see Cluster endpoints and primary endpoints. pc-bpxxxxxxxxxxxxxx.mysql.polardb.rds.aliyuncs.com
-P The port number of the PolarDB cluster.
  • If you use the private endpoint, you must enter the private port number of the PolarDB cluster.
  • If you use a public endpoint, you must enter the public port number of the PolarDB cluster.
Note
  • The default port number is 3306.
  • If you need to use the default port, you can leave this parameter empty.
3306
-u The name of 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 leave this parameter empty, you are required to enter the password when you connect to the cluster.
  • If you configure this parameter, do not enter space characters 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 replace -D with the name of the database.
mysql