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