All Products
Search
Document Center

ApsaraDB for SelectDB:Connect to an instance

Last Updated:Jun 06, 2024

ApsaraDB for SelectDB supports connection over the MySQL protocol. You can connect to an ApsaraDB for SelectDB instance by using tools that are compatible with the MySQL ecosystem, such as command-line tools, Java Database Connectivity (JDBC) or Open Database Connectivity (ODBC) drivers, or visualization tools. This topic describes how to connect to an ApsaraDB for SelectDB instance.

Prerequisites

  • An ApsaraDB for SelectDB instance is in the Running state.

  • The IP address of a 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 public endpoint of the ApsaraDB for SelectDB instance is available if the MySQL client and the ApsaraDB for SelectDB instance are deployed in different virtual private clouds (VPCs). For more information, see Apply for or release a public endpoint.

Procedure

  1. Log on to the ApsaraDB for SelectDB console.

  2. In the top navigation bar, select the region in which the instance that you want to manage resides.

  3. In the left-side navigation pane, click Instances. On the Instances page, click the ID of the instance to go to the Instance Details page.

  4. On the Instance Details page, obtain the VPC endpoint or public endpoint of the instance.ApsaraDB for SelectDB.

  5. Use the MySQL client to connect to the ApsaraDB for SelectDB instance based on its public endpoint or VPC endpoint.

    Syntax:

    mysql -h <Public endpoint or VPC endpoint> -P <MySQL protocol port of the ApsaraDB for SelectDB instance> -u<Database account> -p<Password>

    Sample code:

    mysql -h selectdb-cn-xxx-fe.selectdb.rds.aliyuncs.com -P 9030 -uadmin -pselectdb123
    Note

    If the following information is returned when you connect to the ApsaraDB for SelectDB instance, the IP address or CIDR block of the MySQL client is not added to the IP address whitelist of the ApsaraDB for SelectDB instance:

    ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 2
  6. After you connect to the ApsaraDB for SelectDB instance, select a cluster and query the databases in the cluster. Sample code:

    USE @test_cluster;
    SHOW databases; 

    The following results are returned:

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