Help Center/ TaurusDB/ Getting Started/ Buying a DB Instance and Connecting to It Using the mysql Client
Updated on 2024-12-30 GMT+08:00

Buying a DB Instance and Connecting to It Using the mysql Client

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

Operation Process

Process

Description

Preparations

Sign up for a HUAWEI ID, enable Huawei Cloud services, make sure you have a valid payment method configured, create IAM users, and grant them specific TaurusDB permissions.

Step 1: Buy a DB Instance

Configure information required for instance creation.

Step 2: Buy an ECS

If you want to use the mysql client to connect to a DB instance, you need to prepare a server, install the mysql client on the server, and run the connection command.

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

If you have purchased a Windows ECS, you can connect to the DB instance using MySQL-Front. For details, see Buying a DB Instance and Connecting to It Using MySQL-Front.

Step 3: Test Connectivity and Install the mysql Client

Test the network connectivity between the ECS and the private IP address and port of the DB instance, and install the mysql client on the ECS.

Step 4: Connect to the DB Instance Using the mysql Client

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

Preparations

  1. Sign up for a HUAWEI ID and enable Huawei Cloud services.
  2. Before buying 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 TaurusDB Permissions.

Step 1: Buy a DB Instance

  1. Go to the Buy DB Instance page.
  2. Configure instance information and click Next.
    Figure 1 Selecting a DB engine version

    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

    AP-Singapore

    The region where an instance is located.

    NOTE:

    You cannot change the region of an instance once it is purchased.

    DB Instance Name

    Taurusdb-8293

    The DB instance name.

    DB Engine Version

    TaurusDB V2.0

    The DB engine and version.

    DB Instance Type

    Cluster

    A cluster instance can contain one primary node and up to 15 read replicas. The primary node processes read and write requests, and the read replicas process only read requests. If the primary node becomes unavailable, TaurusDB automatically fails over to a read replica. Cluster instances apply to medium- and large-sized enterprises in the Internet, taxation, banking, and insurance sectors.

    Storage Type

    DL6

    The original Shared storage. The default storage type of TaurusDB instances created before July 2024 is Shared storage, while that of TaurusDB instances created in July 2024 and beyond is DL6.

    DL6-based instances achieve zero RPO with a 3-AZ deployment and deliver better performance and higher peak throughput. They are suitable for core application systems that are sensitive to performance and have demanding requirements on storage I/O during peak hours, such as those in finance, e-commerce, government, and gaming.

    AZ Type

    Multi-AZ

    If your workloads require cross-AZ DR or are insensitive to cross-AZ latency, you are advised to deploy the primary node and read replicas in different AZs to achieve higher availability and reliability.

    Primary AZ

    AZ1

    The primary AZ of an instance.

    Time Zone

    (UTC+08:00) Beijing, Chongqing, Hong Kong, Urumqi

    You need to select a time zone for your instance based on the region hosting your instance. The time zone is selected during instance creation and cannot be changed after the instance is created.

    Figure 2 Selecting specifications

    Parameter

    Example Value

    Description

    Instance Specifications

    Dedicated

    2 vCPUs | 8 GB

    The vCPUs and memory of an instance.

    CPU Architecture

    x86

    x86 instances use Intel® Xeon® Scalable processors and feature robust and stable computing performance. When working on high-performance networks, the instances provide the additional performance and stability that enterprise-class applications demand.

    Nodes

    2

    This parameter is mandatory for cluster instances.

    Storage Space (GB)

    -

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

    Backup Space

    -

    TaurusDB provides free backup space equal to the amount of your used storage. After the free backup space is used up, you will be billed for the additional space on a pay-per-use basis.

    Figure 3 Configuring a network

    Parameter

    Example Value

    Description

    VPC

    default_vpc

    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.

    NOTICE:

    After a TaurusDB instance is created, the VPC cannot be changed.

    Subnet

    default_subnet

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

    Security Group

    default

    The security group enhances security by controlling access to TaurusDB from other services.

    Figure 4 Setting a password

    Parameter

    Example Value

    Description

    Administrator

    root

    The username of the database administrator account. The default username is root.

    Administrator Password

    -

    Must consist of 8 to 32 characters and contain at least three of the following: uppercase letters, lowercase letters, digits, and special characters (~!@#%^*-_=+?,()&$|.). Enter a strong password and periodically change it to improve security, preventing security risks such as brute force cracking.

    Keep your password secure because you cannot retrieve it from the system.

    After a DB instance is created, you can reset this password. For details, see Resetting the Administrator Password.

    Confirm Password

    -

    Enter the administrator password again.

    Parameter Template

    Default-GaussDB-for-MySQL 8.0

    A parameter template contains engine configuration values that can be applied to one or more instances.

    Table Name

    Case insensitive

    Specifies whether table names are case sensitive. This option cannot be changed later.

    • Case sensitive: Table names are case sensitive.
    • Case insensitive: Table names are case insensitive and are stored in lowercase letters by default.

    Enterprise Project

    -

    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.

    Tag

    -

    Tags a DB instance. This parameter is optional. Adding tags helps you better identify and manage your DB instances. Each DB instance can have up to 20 tags.

    Quantity

    1

    You can buy DB instances in batches. The default value is 1. The value ranges from 1 to 10.

  3. Check the purchased DB instance.
    Figure 5 Checking that the DB instance is created
  4. Click the DB instance name to go to the Basic Information page.
  5. In the Network Information area, obtain the private IP address and database port.
    Figure 6 Viewing the private IP address and database port

Step 2: Buy an ECS

  1. Log in to the management console and check whether there is an ECS available.
  2. Buy an ECS and select Linux (for example, CentOS) as its OS.

    To download the 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 DB instance for mutual communications.

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

  3. On the ECS Information page, view the region and VPC of the ECS.
    Figure 7 Viewing basic information about the ECS
  4. On the Basic Information page of the DB instance, view the region and VPC of the DB instance.
    Figure 8 Viewing the region and VPC of the DB instance
  5. Check whether the ECS and DB instance are in the same region and VPC.
    • If they are in the same region and VPC, go to Step 3: Test Connectivity and Install the mysql Client.
    • If they are in different regions, buy 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 they 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 the mysql Client

  1. Log in to the ECS. For details, see Logging In to a Linux ECS Using VNC in Elastic Cloud Server User Guide.
  2. On the ECS, check whether it can connect to the DB instance using the private IP address and port obtained in 5.
    telnet private_IP_address port

    If the message "command not found" is displayed, install the Telnet tool based on the OS used by the ECS.

    • If the ECS can connect to the DB instance, no further action is required.
    • If the ECS cannot connect to the DB instance, check the security group rules.
      • If in the security group associated with the ECS, there is no outbound rule with Destination set to 0.0.0.0/0 and Protocol & Port set to All, add the private IP address and port of the DB instance to the outbound rules.
      • Add the private IP address and port of the ECS to the inbound rules in the security group associated with the DB instance.
  3. Download the mysql client installation package for the Linux ECS.

    You are advised to use a mysql client running a version later than that of the DB instance.

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

  4. Run the following command to install the mysql client:

    rpm -ivh --nodeps mysql-community-client-8.0.21-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.21-1.el6.x86_64.rpm

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

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

Step 4: Connect to the DB Instance Using the mysql Client

  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.*.*.* -P 3306 -u root -p

    Table 1 Parameter description

    Parameter

    Description

    <host>

    The private IP address obtained in 5.

    <port>

    The database port obtained in 5. The default value is 3306.

    <userName>

    The administrator account root.

  2. Enter the password of the database account if the following information is displayed:
    Enter password:
    Figure 9 Connection succeeded
  3. Create database db_test.

    create database db_test;

    Figure 10 Creating a database
  4. Create table t_test.

    create table t_test(id int(4), name char(20), age int(4));

    Figure 11 Creating a table
  5. Insert a data record into the table.

    insert into t_test(id, name, age) values(1, 'zhangsan', 30);

    Figure 12 Inserting data
  6. Query data in the table.

    select * from t_test;

    Figure 13 Querying data
  7. 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 14 Updating data
  8. Query the updated data in the table.

    select * from t_test where id=1;

    Figure 15 Querying the updated data
  9. Delete the data record whose id is 1 from the table.

    delete from t_test where id=1;

    Figure 16 Deleting table data
  10. Delete the table schema.

    drop table t_test;

    Figure 17 Deleting a table schema
  11. Delete the database.

    drop database db_test;

    Figure 18 Deleting a database