nav-img
Advanced

Example: Create and Connect to an RDS for MySQL DB Instance

This example illustrates how to create an RDS for MySQL instance and connect to it from a Linux ECS over a private network.

Figure 1 Example diagram


Step 1: Create an RDS for MySQL DB Instance

  1. Log in to the management console.
  2. Click in the upper left corner and select a region and a project.
  3. Click Service List. Under Database, click Relational Database Service.
  4. On the displayed page, click Create DB Instance.
  5. Configure the instance information and click Apply Now. Keep the region, AZ, VPC, and security group of the DB instance the same as those of the ECS.
  6. View the purchased RDS instance.

Step 2: Create an ECS

  1. Log in to the management console.
  2. Click in the upper left corner and select a region and a project.
  3. Click Service List. Under Compute, click Elastic Cloud Server.
  4. On the displayed page, click Create ECS.
  5. Configure basic settings and click Next: Configure Network. Keep the region and AZ of the ECS the same as those of the RDS for MySQL instance to be connected.
  6. Configure the ECS network information and click Next: Configure Advanced Settings. Keep the VPC and security group of the ECS the same as those of the RDS for MySQL instance to be connected.
  7. Configure the ECS password and click Next: Confirm.
  8. Confirm the configurations and click Apply Now.
  9. View the purchased ECS.

Step 3: Connect to the RDS for MySQL DB Instance

  1. Use a Linux remote connection tool (for example, MobaXterm) to log in to the ECS. Enter the EIP bound to the ECS for Remote host.

    Figure 2 Creating a session


  2. Enter the password of the ECS.

    Figure 3 Entering the password


    Figure 4 Successful login


  3. Download the mysql-community-client-8.0.26-1.el6.x86_64.rpm client installation package by selecting the required product version and operating system.

    Figure 5 Selecting a version


    Figure 6 Downloading the client package


  4. Upload the client installation package to the ECS.

    Figure 7 Uploading the client package


    Figure 8 Package uploaded


  5. Install the client.
    rpm -ivh --nodeps mysql-community-client-8.0.26-1.el6.x86_64.rpm

    Figure 9 Installing the client


  6. Connect to the RDS for MySQL instance.
    mysql -h 192.168.6.198 -P 3306 -u root -p

    Figure 10 Connection successful


  7. Create a database, for example, db_test.
    create database db_test;

    Figure 11 Creating a database


  8. Create a table, for example, t_test.
    create table t_test(id int(4), name char(20), age int(4));

    Figure 12 Creating a table


  9. Insert one data record to the table.
    insert into t_test(id, name, age) values(1, 'zhangsan', 30);

    Figure 13 Inserting data


  10. Query table data.
    select * from t_test;

    Figure 14 Querying data


  11. Update the value of age for the data record whose id is 1 in the table.
    update t_test set age=31 where id=1;

    Figure 15 Updating data


  12. Query the updated table data.
    select * from t_test where id=1;

    Figure 16 Querying updated data


  13. Delete the data record whose id is 1 from the table.
    delete from t_test where id=1;

    Figure 17 Deleting table data


  14. Delete the table structure.
    drop table t_test;

    Figure 18 Deleting table structure


  15. Delete the database.
    drop database db_test;

    Figure 19 Deleting a database