All Products
Search
Document Center

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

Last Updated:Sep 03, 2024

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 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.

  • The MySQL client and ApsaraDB for SelectDB instance reside in the same virtual private cloud (VPC) if you want to connect to the instance over an internal network.

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.

    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             |
    +--------------------+

FAQ

Q: 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

A: Check whether 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.