After you create an ApsaraDB for RDS for MySQL instance and complete the required configuration (creating an account and configuring a whitelist), you can connect to it over an internal network or the internet by using the CLI or a client. Solutions to common connection errors are also provided.
Prerequisites
-
An ApsaraDB for RDS for MySQL instance is created, and a database and database account are created for the instance.
-
An IP address whitelist is configured for the instance.
Recommendations
-
For lower latency and higher stability, connect to your RDS instance from an ECS instance over an internal network. The following conditions must be met for an internal network connection:
The ECS instance and the RDS instance must be in the same Alibaba Cloud account, region, and Virtual Private Cloud (VPC). The private IP address of the ECS instance must be added to the IP address whitelist of the RDS instance.
NoteYou can view the private IP address of your ECS instance on the Instances page.
In the IP Address column of the instance list, a public IP address is marked with "(Public)", and a private IP address is marked with "(Private)".
-
For a public network connection, connect to the database by using its endpoint.
Note-
Run
curl ipinfo.io/ip(recommended) orcurl ifconfig.meto query the public IP address of your local client. -
The public IP address of the RDS instance may change during a database upgrade or migration. If you have added your local IP address to the whitelist but still cannot connect, see the provided solution.
-
Procedure
Connect with the CLI
The following example connects to an ApsaraDB for RDS for MySQL instance from a Linux system. First, install MySQL:
-
On CentOS, run
sudo yum install mysql. -
On Ubuntu, run
sudo apt-get update, and then runsudo apt install mysql-server.
-
Log on to the server that you will use to connect to the RDS instance, such as an ECS instance or a local server.
NoteFor instructions on how to log on to an ECS instance, see the Connect to an ECS instance section in ECS Quick Start.
-
Run the following command to connect:
mysql -h<endpoint> -P<port> -u<username> -pNote-
Enter the password after you run the command.
-
The uppercase letter P specifies the port, and the lowercase letter p specifies the password prompt.
-
Endpoint and port: The endpoint and port of the RDS instance.
Scenario
Required endpoint
How to obtain
You meet the conditions for an internal network connection.
Internal endpoint
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.
-
Click View Details to view the RDS instance address and port number. In the Basic Information section, next to Network Type, click View Connection Details.
Note-
The public endpoint is displayed only after you click Apply for Public Endpoint.
-
For an RDS Cluster Edition instance, you can modify the primary node endpoint in the Cluster Read/Write Connection section and the secondary node endpoint in the Cluster Read-only Connection section.
You are connecting from an ECS instance, but do not meet the conditions for an internal network connection.
Public endpoint
You are connecting from a local device.
-
Username and password: Obtain them from the Accounts page of the RDS instance.
Command example
root@xxx -> mysql -hrxxx.mysql.rds.aliyuncs.com -P3306 -uxxx -p Enter password:Successful connection
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 51325 Server version: 8.0.18 Source distributionNoteIf a connection error occurs, see Common connection errors.
-
Connect with MySQL Workbench
You can also use other general-purpose MySQL clients. The following steps use MySQL Workbench 8.0.29 as an example.
-
Open MySQL Workbench and choose .
-
Enter the connection information and click OK.
From the Connection Method drop-down list, select Standard (TCP/IP).
-
Hostname and Port: The endpoint and port of the RDS instance.
Scenario
Required endpoint
How to obtain
You meet the conditions for an internal network connection.
Internal endpoint
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.
-
Click View Details to view the RDS instance address and port number. In the Basic Information section, next to Network Type, click View Connection Details.
Note-
The public endpoint is displayed only after you click Apply for Public Endpoint.
-
For an RDS Cluster Edition instance, you can modify the primary node endpoint in the Cluster Read/Write Connection section and the secondary node endpoint in the Cluster Read-only Connection section.
You are connecting from an ECS instance, but do not meet the conditions for an internal network connection.
Public endpoint
You are connecting from a local device.
-
Username and Password: Obtain them from the Accounts page of the RDS instance.
-
Connect with Navicat
-
Start the Navicat client.
-
In the upper-left corner, click Connection and select your database type.
NoteIf you use an earlier version of Navicat and the Alibaba Cloud menu is not available, you can directly select a database type, such as MySQL or PostgreSQL.
In the Navicat toolbar, click Connection, select Alibaba Cloud from the drop-down menu, and then select the target database type from the submenu, such as Alibaba Cloud ApsaraDB for RDS (MySQL)..., Alibaba Cloud ApsaraDB for RDS (PostgreSQL)..., or Alibaba Cloud ApsaraDB for RDS (SQL Server)....
-
Enter the connection information for the RDS instance. The following table describes the parameters.
Parameter
Description
Connection Name
A custom name for the connection.
Host
The internal endpoint or public endpoint of the RDS instance.
-
Use the internal endpoint if your client is on an ECS instance in the same account, region, and VPC as the RDS instance.
-
In other cases, use the public endpoint.
Port
The internal port or public port of the RDS instance. For example, the default port for MySQL is 3306.
User Name
The username for the account that accesses the RDS instance. You can find this on the instance's Accounts page.
Password
The password for the specified username.
-
-
Click OK.
NoteIf enhanced whitelist mode is enabled and you want to connect to the instance over the internet, add the public IP address of your client to the classic network group.
After successfully connecting with a client such as Navicat, if you see databases such as
busudab,information_schema, andmysqlin the connection tree, the connection is successful.
Connect from ECS across regions or accounts
-
Public network (Internet) connection: You can use the public endpoint of the RDS instance to connect across regions or accounts. Inbound and outbound Internet traffic to and from the RDS instance is free of charge.
-
Internal network (private network) connection: By default, internal network connections across regions or accounts are not supported because the VPCs are isolated from each other. You can use VPC peering or Cloud Enterprise Network (CEN) to interconnect VPCs, allowing ECS instances to access RDS instances across regions or accounts.
-
VPC peering connection: Supports cross-region and cross-account VPC interconnection at a low cost, but is relatively complex to configure. This option is suitable for simple scenarios that involve a small number of interconnected VPCs.
-
CEN: Supports cross-region and cross-account VPC interconnection with easy configuration, but at a relatively higher cost. This option is suitable for complex scenarios that involve multiple interconnected VPCs.
-
Common connection errors
FAQ
-
Q: Do ApsaraDB for RDS for MySQL instances support Elastic IP Addresses (EIPs)?
A: No, this feature is not currently supported.
-
Q: How do I resolve a Telnet connection failure from my local computer to the RDS instance?
A: If you cannot connect to the RDS instance by using Telnet, check the following:
-
Verify that the service port of the cloud database is correct and open to the internet.
-
Check the security group or firewall rules of the cloud database to ensure that your local IP address is allowed to connect.
-
Verify that the connection parameters, such as the hostname and port number, are correct.
-
Check the firewall rules on your local device to ensure that the port required by RDS is not blocked.
-
If possible, try to connect to the cloud database by using other tools, such as the
mysqlCLI or a database management tool, to rule out Telnet-specific issues.
-
-
Q: How can other users access my database?
A: Follow these steps:
-
Create a standard account and grant it permissions on the database.
-
Configure an IP address whitelist. If the other user is using an ECS instance, add the private IP address or the security group ID of the ECS instance. If the user is using a local MySQL client, add the public IP address of their host device.
-
Share the public endpoint, database name, and account credentials with the user.
-
The user can then connect to the database by using the CLI.
-
References
-
Connection failures: Troubleshoot connection failures
-
A more convenient connection method: Log on to an RDS database by using Data Management Service (DMS)
-
Connect to RDS instances that run other database engines: