Connect to an ApsaraDB for SelectDB instance by using a MySQL client

Updated at: 2025-01-09 06:17

ApsaraDB for SelectDB is compatible with the MySQL protocol and allows you to connect to an ApsaraDB for SelectDB instance by using a MySQL client. This topic describes how to use a MySQL client to connect to an ApsaraDB for SelectDB instance by running commands.

Prerequisites

  • The ApsaraDB for SelectDB instance to which you want to connect is in the Running state.

  • The database connector of the MySQL client is compatible with MySQL 5.7.

  • The network settings of the ApsaraDB for SelectDB instance to which you want to connect are configured based on the network environment of the MySQL client:

    • If the MySQL client is deployed on an Elastic Compute Service (ECS) instance and resides in the same virtual private cloud (VPC) as the ApsaraDB for SelectDB instance, you do not need to configure the network settings of the ApsaraDB for SelectDB instance. You need to only obtain the VPC endpoint of the ApsaraDB for SelectDB instance.

    • In other cases, you must apply for a public endpoint for the ApsaraDB for SelectDB instance. For more information, see Apply for or release a public endpoint.

      Note

      If you use a public endpoint to connect to an ApsaraDB for SelectDB instance, Internet traffic is generated. You are not charged for the generated inbound or outbound Internet traffic.

  • The IP address of the MySQL client is added to the IP address whitelist of the ApsaraDB for SelectDB instance. For more information, see Configure an IP address whitelist.

Procedure

  1. Obtain the endpoint and port number of the instance.

    Log on to the ApsaraDB for SelectDB console. Go to the Instance Details page of the instance that you want to manage and obtain the VPC endpoint, public endpoint, and MySQL port of the instance.

  2. Connect to the instance.

    If you use a public endpoint to connect to an ApsaraDB for SelectDB instance, Internet traffic is generated. You are not charged for the generated inbound or outbound Internet traffic.

    mysql -h <Public or VPC endpoint> -P <MySQL port> -u <Database account> -p<Account password>

    Example

    mysql -h selectdb-cn-*****.selectdbfe.rds.aliyuncs.com -P 9030 -u testdb -pselectdb123
  3. Optional. After you connect to the instance, select a cluster and query the databases in the cluster.

    USE @test_cluster;
    show databases; 

    The following results are returned:

    +--------------------+
    | Database           |
    +--------------------+
    | test               |
    | test01             |
    +--------------------+

References

For more information about data visualization tools, see Data visualization.

FAQ

What do I do if the following error is reported when I connect to an ApsaraDB for SelectDB instance?

ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 2

Check whether the IP address of the MySQL client is added to an IP address whitelist of the ApsaraDB for SelectDB instance. For more information, see Configure an IP address whitelist.

  • On this page (1)
  • Prerequisites
  • Procedure
  • References
  • FAQ
Feedback
phone Contact Us

Chat now with Alibaba Cloud Customer Service to assist you in finding the right products and services to meet your needs.

alicare alicarealicarealicare