All Products
Search
Document Center

Elastic Compute Service:Create and connect to an ApsaraDB RDS instance

Last Updated:Feb 27, 2024

ApsaraDB RDS is a stable, reliable, and scalable online database service. When you use an Elastic Compute Service (ECS) instance to build a business in the cloud, you can use an RDS instance to store business data. This topic describes how to create an ApsaraDB RDS for MySQL instance and connect a Linux ECS instance to the ApsaraDB RDS for MySQL instance.

Prerequisites

An ECS instance is created. For more information, see Create an instance on the Custom Launch tab.

In this topic, an ECS instance that has the following configurations is used. You can configure the ECS instance based on your business requirements.

  • Region and zone: Hangzhou Zone I

  • Instance type: ecs.g6.large

  • Disk category: enhanced SSD (ESSD)

  • Image: Alibaba Cloud Linux 3 64-bit public image

  • Network type: Virtual Private Cloud (VPC). A public IP address is automatically assigned to the instance.

Background information

RDS is built on top of Apsara Distributed File System and high-performance SSDs of Alibaba Cloud. RDS supports the MySQL, SQL Server, PostgreSQL, and MariaDB database engines. RDS provides solutions for scenarios such as disaster recovery, backup, restoration, monitoring, and migration to reduce O&M costs. For more information, see What is ApsaraDB RDS?

Step 1: Create an RDS instance

  1. Go to the ApsaraDB RDS instance buy page.

  2. Complete the configurations of the RDS instance.

    In this example, an ApsaraDB RDS for MySQL instance is created. For more information, see Create an ApsaraDB RDS for MySQL instance. In this example, the following configurations are used. You can configure the RDS instance based on your business requirements.

    1. In the Basic Resources step, configure the following parameters:

      • Region: Select China (Hangzhou).

        Note

        If you want to transmit data between the ECS instance and the RDS instance over the internal network, deploy the ECS instance and the RDS instance in the same region and the same VPC. Compared with the Internet, the internal network is more secure, stable, and efficient for data transmission.

      • Database Engine: Select MySQL 8.0.

      • Edition: Select High-availability Edition.

      • Storage Type: Select Local SSD.

      • Zone of Primary Node: Select Hangzhou Zone I.

      • Deployment Method: Select Multi-zone Deployment.

      • Zone of Secondary Node: Select Automatically Allocated.

      • Instance Type: Select rds.mysql.t1.small.

      Use the default values for other parameters.

    2. Click Next: Instance Configuration.

    3. In the Instance Configuration step, configure the following parameters:

      • Network Type: Select VPC.

      • VPC and vSwitch of Primary Node: Select the same VPC and vSwitch as the ECS instance to which you want to connect.

      Use the default values for other parameters.

    4. Click Next: Confirm Order. Confirm the configurations and complete the payment.

      Up to 10 minutes are required to create an RDS instance. You can view and refresh the status of the RDS instance on the Instances page. If the status of the instance changes to Running, the RDS instance is created and runs as expected.

Step 2: Create a database and a standard account for the database

For information about how to create a database and an account for an ApsaraDB RDS for MySQL instance, see Create accounts and databases. In this example, a database named test01 is created for the RDS instance and a standard account named testuser01 is created. The standard account is used to log on to the test01 database.

  1. Go to the Instances page.

  2. In the top navigation bar, select the China (Hangzhou) region.

  3. Find and click the ID of the RDS instance that you created.

  4. Create a database on the RDS instance.

    1. In the left-side navigation pane of the Basic Information page, click Databases and then click Create Database.

    2. In the Create Database dialog box, configure the following parameters and click Create:

      • Database Name: Specify a name for the database. Example: test01.

      • Supported Character Set: Select utf8.

      Use the default values for other parameters.

  5. Create a standard account.

    1. In the left-side navigation pane, click Accounts. On the Accounts tab, click Create Account.

    2. In the Create Account panel, configure the following parameters and click OK:

      • Database Account: Specify a name for the account. Example: testuser01.

      • Account Type: Select Standard Account.

      • Authorize Database: After you select Standard Account, the Authorize Database section appears. You must grant the read and write permissions on the test01 database to the testuser01 account.授权数据库

      • New Password and Confirm Password: Specify a password. To improve data security, we recommend that you specify a complex password. Keep your password confidential.

      Use the default values for other parameters.

Step 3: Configure a whitelist for the RDS instance and obtain the internal endpoint and internal port number of the RDS instance

Before you obtain the internal endpoint and internal port number of the RDS instance, check whether the ECS instance and the RDS instance meet the conditions for communication over the internal network. For more information, see Use a client or the CLI to connect to an ApsaraDB RDS for MySQL instance. In this example, the ECS instance and the RDS instance belong to the same VPC and can communicate with each other over the internal network.

  1. Go to the Instances page.

  2. In the top navigation bar, select the China (Hangzhou) region.

  3. Find and click the ID of the RDS instance that you created.

  4. Configure a whitelist for the RDS instance

    1. In the left-side navigation pane of the Basic Information page, click Whitelist and SecGroup.

    2. On the Whitelist Settings tab, find the whitelist named default and click Modify on the right side.

    3. In the Edit Whitelist dialog box, remove the default IP address 127.0.0.1 from the IP Addresses field and add <Internal IP address of the ECS instance>.

      For information about how to view the IP address of an ECS instance, see the View the information about instances on the Instances page section in the "View instance information" topic.

    4. Click OK.

  5. Obtain the internal endpoint and internal port number of the RDS instance.

    1. In the left-side navigation pane of the Basic Information page, click Database Connection.

    2. On the Database Connection page, view the values of the Internal Endpoint and Internal Port parameters.

      内网地址

      Save the internal endpoint and internal port number for subsequent connections to the database.

Step 4: Connect to the ApsaraDB RDS for MySQL database from the ECS instance

  1. Log on to the Linux ECS instance.

    For more information, see Connection method overview.

  2. Optional: Install MySQL on the ECS instance.

    If MySQL is not installed on your ECS instance, you must install MySQL. For example, you can run the following command to install MySQL on an ECS instance that runs Alibaba Cloud Linux or CentOS:

    yum -y install mysql
  3. Run the following command to connect to the MySQL database:

    mysql -h<Internal endpoint of the RDS instance> -P<Internal port number of the RDS instance> -u<Standard account of the RDS instance> -p

    Variables:

    • <Internal endpoint of the RDS instance>: the internal endpoint of the RDS instance. Example: rm-bp1bj****.mysql.rds.aliyuncs.com.

    • <Internal port number of the RDS instance>: the internal port number of the RDS instance. For example, the default port number of the MySQL database is 3306.

    • <Standard account of the RDS instance>: the standard account of the RDS instance. In this example, testuser01 is used.

  4. In the Enter password: command line, enter the password of the testuser01 account.

    Note

    For data security purposes, no output is returned when you enter a password. You need only to enter the correct password and then press the Enter key.

    The following figure shows that you are connected to the MySQL database. If the connection fails, see the Common connection errors section in the "Use a client or the CLI to connect to an ApsaraDB RDS for MySQL instance" topic.登录mysql

  5. Optional: Run the following command in the MySQL client to view the details of the database:

    show databases;

    You can view the test01 database in the command output.test01

References

Getting Started