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
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 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 |
If you want to connect to a DB instance using a MySQL client, 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 an RDS for MySQL Instance and Connecting to It Using MySQL-Front. |
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 a CLI (Non-SSL Connection) |
Use a command-line interface (CLI) to connect to the DB instance using the floating IP address and port. |
Procedure
Step 1: Buy an RDS for MySQL DB Instance
- Go to the Buy DB Instance page.
- On the Quick Config page, set basic parameters.
Only mandatory parameters are provided on the Quick Config page. If the available parameters do not match your workloads, try Custom Config.
The following parameter settings are only for reference. Tailor your settings to your workloads.
Figure 1 Basic Settings
Table 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.
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 | 2 vCPU | 4 GB |
The vCPUs and memory of an instance. |
Storage |
Cloud SSD | 100 GB |
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 enhances data security but reduces the database's read and write performance by 5%.
If a shared KMS key is used, the corresponding CTS events are createdatakey and decrydatakey. Only the key owner can receive the events. |
- Set parameters for Additional Options.
Figure 2 Additional Options
Table 2 Additional Options
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 with a Subnet. |
Subnet |
default_subnet |
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 in a batch. |
- Click Buy.
- Check the purchased DB instance.
Figure 3 Instance successfully purchased
Step 2: Buy an ECS
- Go to the Elastic Cloud Server console.
- Check whether there is a Linux ECS.
- If yes, go to 3.
If the ECS image is CentOS, CentOS 7.4 64bit must be used.
- If no, purchase an ECS and select Linux (for example, CentOS 7.4 64bit) 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 a Custom ECS in Elastic Cloud Server User Guide.
- If there is only a Windows ECS, you can use MySQL-Front to connect to the DB instance. For details, see Buying an RDS for MySQL Instance and Connecting to It Using MySQL-Front.
Figure 4 ECS
- Check whether the ECS and RDS for MySQL instance are in the same region and VPC.
Figure 5 ECS information
Figure 6 Overview
- If they are not in the same region, purchase another ECS. 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
- Log in to the ECS. For details, see Logging In to a Linux ECS Using VNC in the Elastic Cloud Server User Guide.
- On the Instances page of the RDS console, check the floating IP address and database port of the DB instance.
Figure 7 Connection information
- After logging in to the ECS, check whether the floating IP address and database port obtained in 2 can be connected.
curl -kv Floating_IP_address:Port
Example:
curl -kv 192.168.0.4:3306
- If yes, network connectivity is normal. Go to 4.
Figure 8 Normal network connectivity
- 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 9 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.
- Download the MySQL client installation package for Linux to the ECS.
A MySQL client running a version later than that of the DB instance is recommended.
- Install the MySQL client.
Step 4: Connect to the DB Instance Using a CLI (Non-SSL Connection)
- 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 3 Parameter description
Parameter |
Example Value |
Description |
<host> |
192.168.6.144 |
Floating IP address obtained in 2. |
<port> |
3306 |
Database port obtained in 2. The default value is 3306. |
<userName> |
root |
Administrator account root. |
- Enter the password of the database account if the following information is displayed:
Enter password:
Figure 11 Connection successful
- Create a database, for example, db_test.
create database db_test;
Figure 12 Creating a database
- Create a table, for example, t_test.
create table t_test(id int(4), name char(20), age int(4));
Figure 13 Creating a table
- Insert one data record to the table.
insert into t_test(id, name, age) values(1, 'zhangsan', 30);
Figure 14 Inserting data
- Query table data.
select * from t_test;
Figure 15 Querying data
- 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 16 Updating data
- Query the updated table data.
select * from t_test where id=1;
Figure 17 Querying updated data
- Delete the data record whose id is 1 from the table.
delete from t_test where id=1;
Figure 18 Deleting table data
- Delete the table structure.
drop table t_test;
Figure 19 Deleting table structure
- Delete the database.
drop database db_test;
Figure 20 Deleting a database
FAQ
What Should I Do If I Forget My Password?
On the Instances page, locate the target DB instance, choose More > Reset Password in the Operation column, and set a new password.
Common Connection Error Messages
- [Warning] Access denied for user 'username'@'yourIp' (using password: NO)
If this error message is displayed when you attempt to connect to an RDS for MySQL instance, check whether the username or password is correct.
- [Warning] Access denied for user 'username'@'yourIp' (using password: YES)
If this error message is displayed when you attempt to connect to an RDS for MySQL instance, check whether the username or password is correct.
- ERROR 2013: Lost connection to MySQL server during query
If the values of wait_timeout and interactive_timeout are too small, the RDS for MySQL client will automatically stop connections that timed out. For details, see RDS for MySQL Client Automatically Disconnected from a DB Instance.
- ERROR 1045 (28000): Access denied for user 'root'@'192.168.0.30' (using password: YES)
Check whether the password is correct, whether the ECS has the permission to connect to the DB instance, and whether the RDS for MySQL client can ping the DB instance's floating IP address. For details, see RDS for MySQL DB Instance Inaccessible.
- ERROR 1226 (42000): User 'test' has exceeded the 'max_user_connections' resource (current value:10)
Check whether the number of connections to the DB instance is limited. For details, see RDS for MySQL DB Instance Inaccessible.
- ERROR 1129 (HY000): Host '192.168.0.111' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'
Check whether the number of failed connection attempts (not caused by incorrect passwords) of the RDS for MySQL client exceeds the value of max_connection_errors. For details, see RDS for MySQL DB Instance Inaccessible.
For more solutions to connection failures, see What Should I Do If I Can't Connect to My RDS DB Instance?
Follow-up Operations
After logging in to the DB instance, you can create or migrate databases.