After you create an ApsaraDB RDS for MySQL instance and complete the required configurations, such as account creation and whitelist setting, you can connect to the RDS instance by using a client or the CLI. This topic describes how to connect to an RDS instance by using a client or the CLI through the Internet or internal networks. This topic also provides describes how to handle common errors related to connection failures.
Prerequisites
An RDS instance is created, and a database and an account are created for the RDS instance. For more information, see Step 1: Create an ApsaraDB RDS for MySQL instance and configure databases.
An IP address whitelist is configured for the RDS instance. For more information, see Configure an IP address whitelist.
Suggestions
If you want to connect to the RDS instance from an Elastic Compute Service (ECS) instance and the ECS instance and the RDS instance meet the following conditions, we recommend that you use an internal endpoint to connect to the RDS instance to achieve the low latency and high stability.
The ECS instance and the RDS instance reside in the same region.
The ECS instance and the RDS instance use the same type of network.
If the ECS instance and the RDS instance both reside in virtual private clouds (VPCs), these instances must reside in the same VPC.
Procedure
Use the CLI to connect to an RDS instance
The following example describes how to connect to an RDS instance from a server that runs Linux. You must install MySQL on the server before the connection. You can run the following commands to install MySQL:
If you use a CentOS operating system, run the
sudo yum install mysql command
.If you use an Ubuntu operating system, run the
sudo apt-get update
command and then thesudo apt install mysql-server
command.
Log on to the server from which you want to connect to the RDS instance. For example, the server can be an ECS instance or an on-premises device.
NoteFor more information about how to log on to an ECS instance, see the "Connect to an instance" section in Create and manage an ECS instance by using the ECS console (express version).
Run the connection command:
mysql -hEndpoint -PPort -uUsername -pPassword
NoteYou can enter the password after you run the command.
The uppercase letter P specifies the port number, and the lowercase letter p specifies the password.
Endpoint and port number: Enter the endpoint and port number that are used to connect to the RDS instance.
Scenario
Endpoint to be obtained
Method to obtain the endpoint
You want to connect to the RDS instance from an ECS instance. The ECS instance and the RDS instance meet the conditions described in the Suggestions section.
Internal endpoint of the RDS instance
Log on to the ApsaraDB RDS console and go to the Instances page. In the top navigation bar, select the region in which the RDS instance resides. Then, find the RDS instance and click the instance ID.
In the Basic Information section of the page that appears, click View Details to the right of the Network Type parameter to view the endpoint and port number that are used to connect to the RDS instance.
NoteBefore you can view the endpoint and port number that are used to connect to the RDS instance, you must configure IP address whitelists for the RDS instance.
The public endpoint is displayed only after a public endpoint is applied for the RDS instance by clicking Apply for Public Endpoint.
You can modify the read/write endpoint of an RDS cluster in the Cluster Read/Write Connection section and modify the read-only endpoint of the RDS cluster in the Cluster Read-only Connection section.
You want to connect to the RDS instance from an ECS instance. The ECS instance and the RDS instance do not meet the conditions for communication over an internal network.
Public endpoint of the RDS instance
You want to connect to the RDS instance from an on-premises device.
Username and password: You can obtain the username and password of the account that is used to connect to the RDS instance from the Accounts page of the instance details page.
Use a client to connect to an RDS instance
You can use a general-purpose MySQL client to connect to an RDS instance. The following example describes how to use MySQL Workbench 8.0.29 to connect to an RDS instance. If you use a different client, the connection operations are similar.
Install MySQL Workbench. For more information, visit the MySQL Workbench download page.
Start MySQL Workbench and choose .
Enter the connection information and click OK.
Hostname and Port: Enter the endpoint and port number that are used to connect to the RDS instance.
Scenario
Endpoint to be obtained
Method to obtain the endpoint
You want to connect to the RDS instance from an ECS instance. The ECS instance and the RDS instance meet the conditions described in the Suggestions section.
Internal endpoint of the RDS instance
Log on to the ApsaraDB RDS console and go to the Instances page. In the top navigation bar, select the region in which the RDS instance resides. Then, find the RDS instance and click the instance ID.
In the Basic Information section of the page that appears, click View Details to the right of the Network Type parameter to view the endpoint and port number that are used to connect to the RDS instance.
NoteBefore you can view the endpoint and port number that are used to connect to the RDS instance, you must configure IP address whitelists for the RDS instance.
The public endpoint is displayed only after a public endpoint is applied for the RDS instance by clicking Apply for Public Endpoint.
You can modify the read/write endpoint of an RDS cluster in the Cluster Read/Write Connection section and modify the read-only endpoint of the RDS cluster in the Cluster Read-only Connection section.
You want to connect to the RDS instance from an ECS instance. The ECS instance and the RDS instance do not meet the conditions for communication over an internal network.
Public endpoint of the RDS instance
You want to connect to the RDS instance from an on-premises device.
Username and Password: You can obtain the username and password of the account that is used to connect to the RDS instance from the Accounts page of the instance details page. .
Common connection errors
References
For more information about how to troubleshoot connection errors, see What do I do if I fail to connect to an ApsaraDB RDS instance?
For more information about how to connect to an RDS instance in a more convenient and efficient manner, see Use DMS to log on to an ApsaraDB RDS for MySQL instance.
For more information about how to connect to an RDS instance that runs a different database engine, see the following topics: