All Products
Search
Document Center

ApsaraDB RDS:Step 2: Connect to an ApsaraDB RDS for MySQL instance

Last Updated:Oct 11, 2024

After you create an ApsaraDB RDS for MySQL instance and a database, you must manually connect to the RDS instance to manage data or connect your application server to the database for service deployment. This topic describes how to log on to an RDS instance by using Data Management (DMS) or connect to the RDS instance by using the CLI or a client. You can select a logon or connection method based on your business requirements.

Billing rules

  • After you create an RDS instance, you are charged for the instance specifications and the storage capacity of the RDS instance. The fees that are generated for the RDS instance vary based on the billing method, RDS edition, instance type, storage type, and storage capacity. For more information, see Billable items.

  • In the topic, the fees do not include the fees for the application server and third-party client that are used to connect to the RDS instance.

Preparations

  • You must create an RDS instance, a MySQL database on the RDS instance, and a privileged account for the RDS instance. For more information, see Step 1: Create an ApsaraDB RDS for MySQL instance and configure databases.

    Important

    In this topic, you can use the RDS instance, database, and account that are created and configured in Step 1: Create an ApsaraDB RDS for MySQL instance and configure databases. You can also modify the configurations based on your business requirements.

  • If you want to use DMS to log on to the RDS instance, you can skip the Preparations section.

  • If you want to use the CLI or a client to log on to the RDS instance, you must configure an IP address whitelist for the RDS instance and obtain the internal endpoint or public endpoint of the RDS instance based on the connection type. The following section describes the detailed operations.

    Configure an IP address whitelist and select an appropriate connection type

    1. Configure an IP address whitelist

    You must add your IP address or the IP address of your application server to an IP address whitelist of the RDS instance before you can connect to the RDS instance. For more information, see Configure an IP address whitelist. You can obtain the internal endpoint or public endpoint of the RDS instance only after you configure an IP address whitelist.

    2. Select an appropriate connection type

    You can connect to the RDS instance over an internal network or the Internet. If you want to connect to the RDS instance over an internal network, you must use the internal endpoint of the RDS instance. If the conditions for communication over an internal network are not met or you want to connect to the RDS instance from an on-premises device, you must use the public endpoint of the RDS instance. The following list describes the conditions that must be met to connect to an RDS instance over an internal network and how to obtain the internal endpoint and public endpoint of the RDS instance.

    Important

    If you want to connect to the RDS instance over an internal network, make sure that the following conditions are met:

    • If you want to connect to the RDS instance from an Elastic Compute Service (ECS) instance, make sure that the ECS instance and the RDS instance reside in the same region and use the same network type.

    • If the ECS instance and the RDS instance use the virtual private cloud (VPC) network type, make sure that the instances reside in the same VPC.

    Scenario

    Endpoint to be obtained

    Method to obtain the endpoint

    You want to connect to the RDS instance, and the conditions for communication over an internal network are met.

    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
    • The public endpoint is displayed only after a public endpoint is applied for the RDS instance. To view the public endpoint, click 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, but the conditions for communication over an internal network are not met.

    Public endpoint of the RDS instance

    You want to connect to the RDS instance from an on-premises device.

Method 1: Log on to the RDS instance in the DMS console

DMS is a one-stop data management platform that allows you to manage data throughout its lifecycle. You can use DMS to manage global data assets, govern data, design and develop databases, integrate data, develop data, and consume data. These features help enterprises obtain value from data in an efficient and secure manner and facilitate the digital transformation of enterprises. For more information, see What is DMS?

You can use DMS to log on to your RDS instance to manage and use data without the need to configure IP address whitelists or connection types for 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 your RDS instance resides, find the RDS instance, and then click the instance ID.

  2. On the page that appears, click Log In to go to the logon page of the DMS console. image

  3. In the Log On to Database Instance dialog box, enter the logon information and click Login.

    • Configure the Access Mode parameter. In this topic, Account + password login is selected.

    • Configure the Database Account and Database Password parameters. In this topic, a privileged account named dbuser and a custom password are used.

    • Configure the Control Mode parameter. In this topic, Flexible Management is selected.

      Note
      • If your RDS instance is managed in Flexible Management mode, you can use DMS to manage the instance free of charge. If your RDS instance is managed in Stable Change or Security Collaboration, fees are generated. For more information, see Pricing.

      • Compared with the Flexible Management mode, the Stable Change and Security Collaboration modes provide more features and enhanced database management capabilities. If your RDS instance is for trial use, we recommend that you select Flexible Management. For more information, see Control modes.

      image

  4. View a database. In the left-side navigation pane of the DMS console, choose Database Instances > Instances Connected to view the created database. In this topic, the db_test1 database is displayed. You can also double-click your database. image

    Note
    • information_schema, mysql, performance_schema, sys, and __recycle_bin__ are system databases.

    • If the RDS instance exists but you cannot find the required database, the metadata may not be synchronized. To find the required database, move the pointer over the RDS instance to which the required database belongs and click the refresh icon next to the instance name.

Method 2: Use the CLI to connect to the RDS instance

If you want to use server commands to manage a database and you want to connect to the database from an ECS instance or an on-premises device, you can use the CLI to connect to the RDS instance on which the database is created. In this topic, a Linux operating system is used to describe how to use the CLI to connect to an RDS instance.

Important
  • Before you can use the CLI to connect to an RDS instance, you must configure an IP address whitelist for the RDS instance and obtain the endpoint of the RDS instance based on your business requirements.

  • Before you can use the CLI to connect to an RDS instance, you must install MySQL on the application server. The commands that you can use to install MySQL vary based on the Linux distributions.

    • CentOS

      sudo yum install mysql
    • Ubuntu

      sudo apt-get update
      sudo apt install mysql-server
  1. Log on to the application server to which you want to connect the RDS instance. You can connect to the RDS instance from the on-premises device or an ECS instance. For more information about how to log on to an ECS instance, see Follow the wizard to complete the configurations to purchase an ECS instance.

  2. Run the command for database connection, enter the password, and then connect to the RDS instance. In this example, the following command is used. In the command, h specifies the endpoint of the RDS instance, P specifies the port number of the RDS instance, u specifies the username of your database account, and p specifies the password of the database account. The password is required after you run the command

    # Command template
    mysql -hEndpoint of the RDS instance -PPort number-uUsername -p
    
    # Sample command
    mysql -hrm-bp**************.mysql.rds.aliyuncs.com -P3306 -udbuser -p
    • Specify the endpoint. You must determine whether the RDS instance can be connected over an internal network based on your business requirements and specify the required endpoint. In this topic, an internal endpoint is used. For more information about how to determine whether an RDS instance can be connected over an internal network and how to obtain the internal or public endpoint, see Preparations.

    • Specify the port. In this topic, port 3306 is used.

    • Specify the username. In this topic, a privileged account named dbuser is used.

    • Press the Enter key, enter the password of the privileged account in Enter password, and then run the command for database connection.

  3. If the information similar to the following figure is displayed on the CLI, the RDS instance is connected. Then, you can perform subsequent operations. image

Method 3: Use a client to connect to the RDS instance

If you are unfamiliar with complex server commands, you can also use a common third-party client to connect to the RDS instance. In this topic, MySQL Workbench 8.0.29 is used as an example to describe how to connect to an RDS instance from a client.

Important
  • To connect to an RDS instance from a client, you must configure an IP address whitelist for the RDS instance and obtain the endpoint of the RDS instance based on your business requirements.

  • You must download and install MySQL Workbench 8.0.29 in advance. For more information, visit the MySQL Workbench download page.

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

  2. On the Connect to Database page, enter the information about the required connection address and the account. 连接界面

    • Configure the Connection Method parameter. In this topic, Standard(TCP/IP) is used.

    • Configure the Hostname parameter. You must determine whether the RDS instance can be connected over an internal network based on your business requirements and specify the required endpoint. In this topic, an internal endpoint is used. For more information about how to determine whether an RDS instance can be connected over an internal network and how to obtain the internal or public endpoint, see Preparations.

    • Configure the Port parameter. In this topic, port 3306 is used.

    • Configure the Username parameter. In this topic, the privileged account named dbuser is used.

    • Configure the Password parameter. You must specify a custom password.

  3. Click OK to connect to the RDS instance. Then, you can perform subsequent operations.

Common errors and solutions

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 that require SSL encryption for standard TCP/IP connections. However, the connected server does not support SSL encryption. In this case, you can download MySQL Workbench 8.0.29 that is used in this topic 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 invalid. For more information, see Configure an IP address whitelist.

  • In some cases, this error occurs because the RDS instance and the ECS instance do not meet the conditions for communication over an internal network but you attempt to connect to the internal endpoint of the RDS instance.

Cannot Connect to Database Server

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

  • In some cases, this error occurs because the RDS instance and the ECS instance do not meet the conditions for communication over an internal network but 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 invalid. For more information, see Configure an IP address whitelist for an ApsaraDB RDS for MySQL instance.

  • In some cases, this error occurs because the RDS instance and the ECS instance do not meet the conditions for communication over an internal network but you attempt to connect to the internal endpoint of the RDS instance.

The "Destination Host Unreachable" error message is 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.

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

How do I use Function Compute to obtain data from my RDS instance?

You can install third-party dependencies for your functions in Function Compute and use built-in modules to obtain the data of your RDS instance. For more information, see Install third-party dependencies for a function.

References