All Products
Search
Document Center

ApsaraDB RDS:Use a client or the CLI to connect to an ApsaraDB RDS for MySQL instance

Last Updated:Jan 20, 2025

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

Suggestions

  • If the conditions for connections over an internal network are met, we recommend that you use an internal endpoint to connect to the RDS instance to achieve the low latency and high stability.

    Conditions for connections over an internal network

    If you want to connect an Elastic Compute Service (ECS) instance to the RDS instance over an internal network, the following conditions must be met:

    • The ECS instance and the RDS instance use the same network type.

    • If the ECS instance and the RDS instance both reside in virtual private clouds (VPCs), the instances must reside in the same VPC.

    • The private IP address of the ECS instance is added to an IP address whitelist of the RDS instance. For more information, see Configure a whitelist.

  • If you want to connect to the RDS instance over the Internet, we recommend that you use the instance endpoint instead of the public IP address because the public IP address may change during the instance upgrade or specification change.

    Note

    You can run the curl ipinfo.io/ip command to query the public IP address of the on-premises client.

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 the sudo apt install mysql-server command.

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

    Note

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

  2. Run the connection command:

    mysql -hEndpoint -PPort -uUsername -pPassword
    Note
    • You 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 for communication over an internal network.

      Internal endpoint of the RDS instance

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

      2. 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. 查看连接详情

      Note
      • Before 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.

    Example command示例

    Connection established连接成功

    Note

    If connection errors occur, you can resolve the errors by following the instructions provided in Common connection errors.

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.

  1. Install MySQL Workbench. For more information, visit the MySQL Workbench download page.

  2. Start MySQL Workbench and choose Database > Connect to Database.

  3. 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 for communication over an internal network.

      Internal endpoint of the RDS instance

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

      2. 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. 查看连接详情

      Note
      • Before 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

mysql command not found

This error occurs because MySQL is not installed. 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 the sudo apt install mysql-server command.

SSL connection error: SSL is required but the server doesn't support it

You are using specific versions of MySQL Workbench. In these versions, standard TCP/IP connections require SSL encryption. However, the connected server does not support SSL encryption. In this case, you can download the version of MySQL Workbench that is described in this section to establish regular connections.

Error code 10060: Can't connect to MySQL server on 'rm-bpxxx.mysql.rds.aliyuncs.com'(10060)

  • In most cases, this error occurs because the IP address whitelists that you configure are inappropriate. For more information, see Configure an IP address whitelist.

  • In a few cases, this error occurs because the RDS instance and the ECS instance do not meet the conditions described in the Suggestions section. However, you attempt to connect to the internal endpoint of the RDS instance.

Error code 113: Can't connect to MySQL server on 'rm-bpxxx.mysql.rds.aliyuncs.com'(113)

Cannot Connect to Database Server

  • In most cases, this error occurs because the IP address whitelists that you configure are inappropriate. For more information, see Configure an IP address whitelist.

  • In a few cases, this error occurs because the RDS instance and the ECS instance do not meet the conditions described in the Suggestions section. However, you attempt to connect to the internal endpoint of the RDS instance.

Your connection attempt failed for user 'xx" to the MySQL server

  • In most cases, this error occurs because the IP address whitelists that you configure are inappropriate. For more information, see Configure an IP address whitelist.

  • In a few cases, this error occurs because the RDS instance and the ECS instance do not meet the conditions described in the Suggestions section. However, you attempt to connect to the internal endpoint of the RDS instance.

The "Destination Host Unreachable" error message reported when you ping the internal endpoint of the RDS instance

Access denied for user 'xxx'@'xxx'(using password:YES)

This error occurs because the username and password that you entered are incorrect. You can obtain the correct username and password from the Accounts page of the instance details page.

Unknown MySQL server host 'xxx'(11001)

This error occurs because the endpoint that you entered is invalid. Valid endpoints are in the rm-xxxxxx.mysql.rds.aliyuncs.com format.

FAQ

  • Do RDS instances support elastic IP addresses (EIPs)?

    No, RDS instances do not support EIPs.

  • How do I connect the ECS instance and the RDS instance if they do not reside in the same VPC or region?

    You can use VPC peering connections or Cloud Enterprise Network (CEN) instances to enable the inter-VPC communication. For more information, see VPC peering connections and Attach a VPC to a CEN instance.

  • How do I resolve the issue that I fail to use Telnet to connect my computer to an RDS instance?

    If you fail to use Telnet to connect my computer to an RDS instance, you can check the following items:

    • Whether the service port of the RDS instance is correct and accessible over the Internet.

    • Whether the security group or firewall rule of the RDS instance allows the access requests from the IP address of your computer.

    • Whether the connection parameters, such as the hostname and port number, are correctly configured.

    • Whether the issue is a Telnet-specific issue. You can use other methods, such as the mysql client or database management tool, to connect to the RDS instance for the check.

References