ApsaraDB RDS is a stable, reliable, and scalable online database service. When you use an Elastic Compute Service (ECS) instance to build a business on the cloud, you can use an RDS instance to store business data. This topic describes how to create an ApsaraDB RDS for MySQL instance and connect a Linux ECS instance to the ApsaraDB RDS for MySQL instance.
Prerequisites
An ECS instance is created. For more information, see Create an instance by using the wizard.
- Region and zone: Hangzhou Zone I
- Instance type: ecs.g6.large
- Disk category: enhanced SSD (ESSD)
- Image: Alibaba Cloud Linux 3 64-bit public image
- Network type: Virtual Private Cloud (VPC). A public IP address is assigned to the instance.
Background information
RDS is built on top of the Apsara Distributed File System and high-performance SSDs of Alibaba Cloud. RDS supports the MySQL, SQL Server, PostgreSQL, and MariaDB database engines. It provides a portfolio of solutions for scenarios such as disaster recovery, backup, restoration, monitoring, and migration to reduce your O&M burdens. For more information, see What is ApsaraDB RDS?
Step 1: Create an RDS instance
- Go to the ApsaraDB RDS buy page.
- Complete the configurations of the RDS instance. In this example, an ApsaraDB RDS for MySQL instance is created. For more information about how to create an ApsaraDB RDS for MySQL instance, see Create an ApsaraDB RDS for MySQL instance. In this example, the following configurations are used. You can configure the RDS instance based on your business requirements.
Step 2: Create a database and a standard account for the database
For information about how to create a database and an account for an ApsaraDB RDS for MySQL instance, see Create databases and accounts for an ApsaraDB RDS for MySQL instance. In this example, a database named test01
is created for the RDS instance and a standard account named testuser01
is created to log on to the test01
database.
- Go to the Instances page.
- In the top navigation bar, select the China (Hangzhou) region.
- Find and click the ID of the RDS instance that you created.
- Create a database on the RDS instance.
- Create a standard account.
Step 3: Configure a whitelist for the RDS instance and obtain the internal endpoint and internal port number of the RDS instance
Before you obtain the internal endpoint and internal port number of the RDS instance, you must check whether the ECS instance and the RDS instance meet the conditions for communication over the internal network. For more information, see the "Step 1: Check whether your application can connect to the RDS instance over an internal network" section in Use a database client or the CLI to connect to an ApsaraDB RDS for MySQL instance. In this example, the ECS instance and the RDS instance reside within the same VPC and are able to communicate with each other over the internal network.
- Go to the Instances page.
- In the top navigation bar, select the China (Hangzhou) region.
- Find and click the ID of the RDS instance that you created.
- Configure a whitelist for the RDS instance.
- Obtain the internal endpoint and internal port number of the RDS instance.
Step 4: Connect to the ApsaraDB RDS for MySQL database from the ECS instance
- Log on to the Linux ECS instance. For more information, see Connection methods .
- Optional: Install MySQL on the ECS instance. If MySQL is not installed on your ECS instance, install MySQL first. For example, you can run the following command to install MySQL on an ECS instance that runs Alibaba Cloud Linux or CentOS:
yum -y install mysql
- Run the following command to connect to the MySQL database:
Variables:mysql -h <Internal endpoint of the RDS instance> -P <Internal port number of the RDS instance> -u<Standard account of the RDS instance> -p
- <Internal endpoint of the RDS instance>: the internal endpoint of the RDS instance. Example:
rm-bp1bj****.mysql.rds.aliyuncs.com
. - <Internal port number of the RDS instance>: the internal port number of the RDS instance. For example, the default port number of the MySQL database is 3306.
- <Standard account of the RDS instance>: the standard account of the RDS instance. In this example,
testuser01
is used.
- <Internal endpoint of the RDS instance>: the internal endpoint of the RDS instance. Example:
- In the Enter password: command line, enter the password of
testuser01
.Note When you enter a password, no command output is returned to maximize data security. You need only to enter the correct password and then press the Enter key.The following figure shows that you are connected to the MySQL database. If the connection fails, see the "Common connection errors" section in Common connection errors. - Optional: Run the following command in the MySQL client to view the details of the database:
show databases;
You can view thetest01
database in the command output.