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
Log on to the ApsaraDB for SelectDB console.
In the top navigation bar, select the region in which the instance that you want to manage resides.
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.
On the Instance Details page, obtain the VPC endpoint or public endpoint of the instance.ApsaraDB for SelectDB.
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
NoteIf 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
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 | +--------------------+