Help Center/ Relational Database Service/ Getting Started/ Getting Started with RDS for MySQL/ Buying a DB Instance and Connecting to It Using a MySQL Client
Updated on 2024-09-30 GMT+08:00

Buying a DB Instance and Connecting to It Using a MySQL Client

After buying a DB instance, you can connect to it using a Linux ECS with a MySQL client installed over a private network. This section describes how to access a DB instance from an ECS using a standard MySQL client.

This section introduces how to connect to a DB instance with SSL disabled. To connect to a DB instance with SSL enabled, see Using MySQL CLI to Connect to an Instance Through a Private Network.

Operation Process

Step

Description

Preparations

Sign up for a HUAWEI ID, enable Huawei Cloud services, top up your account, create IAM users, and grant them specific RDS permissions.

Step 1: Buy an RDS for MySQL DB Instance

Select required basic settings and additional options and buy an RDS for MySQL DB instance.

Step 2: Buy an ECS

Purchase a Linux ECS that is in the same region and VPC as your DB instance.

Step 3: Test Connectivity and Install a MySQL Client

Test the network connectivity between the ECS and the floating IP address and port of the DB instance, and install a MySQL client on the ECS.

Step 4: Connect to the DB Instance Using Commands (Non-SSL Connection)

Use a command-line interface (CLI) to connect to the DB instance using the floating IP address and port.

Preparations

  1. Sign up for a HUAWEI ID and enable Huawei Cloud services.
  2. Before purchasing DB instances, ensure that your account balance is sufficient. Top up your account if required.
  3. For fine-grained permissions management on Huawei Cloud resources, use Identity and Access Management (IAM) to create a user or user group and grant it specific operation permissions. For details, see Creating a User and Granting Permissions.

Step 1: Buy an RDS for MySQL DB Instance

  1. Go to the Buy DB Instance page.
  2. On the Quick Config page, set basic parameters.

    Only mandatory parameters are provided on the Quick Config page. For more parameters, see Buy a DB Instance.

    The following configuration items are only for reference. Select right resources to match your workloads.

    Figure 1 Basic Settings

    Parameter

    Example Value

    Description

    Billing Mode

    Pay-per-use

    The billing mode of an instance.

    • Yearly/Monthly: A prepaid billing mode in which you pay for resources before using it. Bills are settled based on the subscription period. The longer the subscription, the bigger the discount. This mode is a good option for long-term, stable services.
    • Pay-per-use: A postpaid billing mode. You pay as you go and just pay for what you use. The DB instance usage is calculated by the second but billed every hour. This mode allows you to adjust resource usage easily. You neither need to prepare for resources in advance, nor end up with excessive or insufficient preset resources.

    Region

    CN-Hong Kong

    The region where your resources are located.

    NOTE:

    Products in different regions cannot communicate with each other through a private network. After a DB instance is created, the region cannot be changed. Therefore, exercise caution when selecting a region.

    DB Engine Version

    8.0

    The database version.

    DB Instance Type

    Primary/Standby

    The architecture type of an instance.

    Primary/Standby: An HA architecture. In a primary/standby pair, each instance has the same instance class. When a primary instance is being created, a standby instance is provisioned along with it to provide data redundancy. The standby instance is invisible to you after being created.

    Instance Class

    General-purpose | 2U | 4G

    The vCPU and memory of an instance.

    Storage

    Cloud SSD | 100GB

    The storage space of an instance.

    It contains the system overhead required for inodes, reserved blocks, and database operation.

    Disk Encryption

    Disable

    Enabling disk encryption improves data security, but slightly affects the read and write performance of the database.

  3. Complete advanced configurations.
    Figure 2 Additional Options

    Parameter

    Example Value

    Description

    VPC

    vpc-default

    The virtual network in which your instance is located. A VPC can isolate networks for different workloads.

    If no VPC is available, click Create VPC. After a VPC is created, click . For details, see Creating a VPC and Subnet.

    Subnet

    subnet-default

    A subnet provides dedicated network resources that are logically isolated from other networks for network security.

    Security Group

    default

    It can enhance security by controlling access to RDS for MySQL from other services.

    Enterprise Project

    default

    If your account has been associated with an enterprise project, select the target project from the Enterprise Project drop-down list.

    For more information about enterprise projects, see Enterprise Management User Guide.

    Table Name

    Case insensitive

    Whether table names are case sensitive. Restoration may fail if the case sensitivity settings of table names on the source and target instances are different.

    The case sensitivity of table names for created RDS for MySQL 8.0 instances cannot be changed.

    Quantity

    1

    The number of instances to be created.

  4. Click Buy.
  5. Check the purchased DB instance.
    Figure 3 Instance successfully purchased

Step 2: Buy an ECS

  1. Go to the Elastic Cloud Server console.
  2. Check whether there is an Elastic Cloud Server (ECS) in the CN-Hong Kong region.
    Figure 4 ECS
  3. Buy an ECS and select Linux (for example, CentOS) as its OS.

    To download a MySQL client to the ECS, bind an EIP to the ECS. The ECS must be in the same region, VPC, and security group as the RDS for MySQL DB instance for mutual communications.

    For details about how to purchase a Linux ECS, see "Purchasing an ECS" in Elastic Cloud Server Getting Started.

  4. On the ECS Information page, check the VPC of the ECS.

  5. On the Overview page of the RDS for MySQL instance, check the VPC of the DB instance.
    Figure 5 Overview

  6. Ensure that the ECS and RDS for MySQL instance are in the same region and VPC. Then go to Step 3: Test Connectivity and Install a MySQL Client.
    • If they are not in the same region, purchase another ECS or DB instance. The ECS and DB instance in different regions cannot communicate with each other. To reduce network latency, deploy your DB instance in the region nearest to your workloads.
    • If the ECS and DB instance are in different VPCs, change the VPC of the ECS to that of the DB instance. For details, see Changing a VPC.

Step 3: Test Connectivity and Install a MySQL Client

  1. Log in to the ECS. For details, see Login Using VNC in the Elastic Cloud Server User Guide.
  2. On the Instances page of the RDS console, click the DB instance name.
  3. Choose Connectivity & Security from the navigation pane. In the Connection Information area, obtain the floating IP address and database port of the DB instance.
    Figure 6 Connection information

  4. On the ECS, check whether the floating IP address and database port of the DB instance can be connected.

    telnet 192.168.6.144 3306

    • If yes, network connectivity is normal.
    • If no, check the security group rules.
      • Check the outbound rules of the ECS security group. By default, all outgoing network traffic is allowed.
        If not all outgoing traffic is allowed, add an outbound rule for the floating IP address and port of the DB instance.
        Figure 7 ECS security group
      • If in the security group of the DB instance, there is no inbound rule allowing the access from the private IP address and port of the ECS, add an inbound rule for the private IP address and port of the ECS. For details, see Configuring a Security Group Rule.
  5. Download the MySQL client installation package for Linux to the ECS. The package mysql-community-client-8.0.28-1.el6.x86_64.rpm is used as an example.

    wget https://dev.mysql.com/get/mysql-community-client-8.0.28-1.el6.x86_64.rpm

    A MySQL client running a version later than that of the DB instance is recommended.

  6. Install the MySQL client.

    rpm -ivh --nodeps mysql-community-client-8.0.28-1.el6.x86_64.rpm

    • If any conflicts occur during the installation, add the replacefiles parameter to the command and install the client again.

      rpm -ivh --replacefiles mysql-community-client-8.0.28-1.el6.x86_64.rpm

    • If a message is displayed prompting you to install a dependent package during the installation, add the nodeps parameter to the command and install the client again.

      rpm -ivh --nodeps mysql-community-client-8.0.28-1.el6.x86_64.rpm

Step 4: Connect to the DB Instance Using Commands (Non-SSL Connection)

  1. Run the following command on the ECS to connect to the DB instance:

    mysql -h <host> -P <port> -u <userName> -p

    Example:

    mysql -h 192.168.6.144 -P 3306 -u root -p

    Table 1 Parameter description

    Parameter

    Description

    <host>

    Floating IP address obtained in 3.

    <port>

    Database port obtained in 3. The default value is 3306.

    <userName>

    Administrator account root.

  2. Enter the password of the database account if the following information is displayed:
    Enter password:
    Figure 8 Connection successful

Follow-up Operations

After logging in to the DB instance, you can create or migrate databases.