Updated on 2024-09-12 GMT+08:00
Example: Buy and Connect to an RDS for MySQL DB Instance
This example illustrates how to purchase an RDS for MySQL instance and connect to it from a Linux ECS over a private network.
- Step 1: Create an RDS for MySQL DB Instance
- Step 2: Create an ECS
- Step 3: Connect to the RDS for MySQL DB Instance
Figure 1 Example diagram
Step 1: Create an RDS for MySQL DB Instance
- Go to the Buy DB Instance page.
- Configure the instance information and click Next. Keep the region, AZ, VPC, and security group of the DB instance the same as those of the ECS.
Figure 2 Selecting an engine version
Figure 3 Selecting an instance class
Figure 4 Configuring network information
Figure 5 Setting a password
- View the purchased RDS instance.
Figure 6 Instance successfully purchased
Step 2: Create an ECS
- Go to the Buy ECS page.
- 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.
Figure 7 Basic settings
Figure 8 Selecting an image
- 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.
Figure 9 Network settings
Figure 10 Selecting an EIP
- Configure the ECS password and click Next: Confirm.
Figure 11 Advanced settings
- Confirm the configurations and click Submit.
Figure 12 Confirming the configurations
- View the purchased ECS.
Step 3: Connect to the RDS for MySQL DB Instance
- 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 13 Creating a session
- Enter the password of the ECS.
Figure 14 Entering the password
Figure 15 Successful login
- 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 16 Selecting a version
Figure 17 Downloading the client package
- Upload the client installation package to the ECS.
Figure 18 Uploading the client package
Figure 19 Package uploaded
- Install the client.
rpm -ivh --nodeps mysql-community-client-8.0.26-1.el6.x86_64.rpm
Figure 20 Installing the client
- Connect to the RDS for MySQL instance.
mysql -h 192.168.6.198 -P 3306 -u root -p
Figure 21 Connection successful
- Create a database, for example, db_test.
create database db_test;
Figure 22 Creating a database
- Create a table, for example, t_test.
create table t_test(id int(4), name char(20), age int(4));
Figure 23 Creating a table
- Insert one data record to the table.
insert into t_test(id, name, age) values(1, 'zhangsan', 30);
Figure 24 Inserting data
- Query table data.
select * from t_test;
Figure 25 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 26 Updating data
- Query the updated table data.
select * from t_test where id=1;
Figure 27 Querying updated data
- Delete the data record whose id is 1 from the table.
delete from t_test where id=1;
Figure 28 Deleting table data
- Delete the table structure.
drop table t_test;
Figure 29 Deleting table structure
- Delete the database.
drop database db_test;
Figure 30 Deleting a database
Parent topic: Getting Started with RDS for MySQL
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot