Connecting to a DB Instance over a Private Network
If your applications are deployed on an ECS that is in the same region and VPC as your DB instance, connect the ECS to the DB instance through a private IP address.
This section describes how to connect a Linux ECS to a DB instance with SSL enabled through a private IP address. SSL encrypts connections to the DB instance, making data more secure.
Step 1: Buy an ECS
- Log in to the management console and check whether there is an ECS available.
- If there is a Linux ECS, go to 3.
- If there is a Windows ECS, see Connecting to a DB Instance Through MySQL-Front.
- If no ECS is available, go to 2.
Figure 1 ECS - 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 and Using a Linux ECS (New Edition) in Elastic Cloud Server Getting Started.
- On the ECS Information page, view the region and VPC of the ECS.
Figure 2 ECS information
- On the Basic Information page of the DB instance, view the region and VPC of the DB instance.
- 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 2: Test Connectivity and Install the mysql Client.
- If they are in different regions, buy another 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 2: Test Connectivity and Install the 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 TaurusDB console, click the instance name to go to the Basic Information page.
- In the Figure 3 Viewing the private IP address and database port
area, obtain the private IP address and database port.
- On the ECS, check whether the private IP address and database port of the DB instance can be connected.
curl -kv Floating_IP_address:Port
Example:
curl -kv 192.168.6.144:3306
- If yes, network connectivity is normal.
Figure 4 Normal network connectivity
- If no, check the security group rules.
- If in the security group of 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.
Figure 5 ECS security group
- If in the security group of the DB instance, there is no inbound rule with Source set to 0.0.0.0/0 and Protocol & Port set to All, add the private IP address and port of the ECS to the inbound rules. For details, see Configuring Security Group Rules.
Figure 6 Security group of a DB instance
- If in the security group of 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.
- If yes, network connectivity is normal.
- Import a MySQL client installation package to the ECS using Method 1 or Method 2 and install the client.
- Download a MySQL client installation package for Linux using the ECS. To do so, you need to bind an EIP to the ECS.
mysql-community-client-8.0.24-1.el8.x86_64.rpm is used as an example.
wget https://dev.mysql.com/get/mysql-community-client-8.0.24-1.el8.x86_64.rpm
A MySQL client running a version later than that of the DB instance is recommended.
- Run the following command to install the MySQL client:
rpm -ivh --nodeps mysql-community-client-8.0.24-1.el8.x86_64.rpm
Figure 7 Installing a client- 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-installation_package_version-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-installation_package_version-1.el6.x86_64.rpm
- If any conflicts occur during the installation, add the replacefiles parameter to the command and install the client again.
- Download a MySQL client installation package for Linux using a browser and upload the package to the ECS.
You can use any terminal connection tool, such as WinSCP and PuTTY, to upload the installation package to the ECS.
Click here to download an installation package. mysql-community-client-8.0.24-1.el8.x86_64.rpm is used as an example.
Figure 8 Downloading a MySQL 8.0 installation packageA MySQL client running a version later than that of the DB instance is recommended.
- Run the following command to install the MySQL client:
rpm -ivh --nodeps mysql-community-client-8.0.24-1.el8.x86_64.rpm
Figure 9 Installing a client- 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-installation_package_version-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-installation_package_version-1.el6.x86_64.rpm
- If any conflicts occur during the installation, add the replacefiles parameter to the command and install the client again.
Step 3: Connect to the DB Instance Using a CLI
On the Instances page of the TaurusDB console, click the instance name to go to the Basic Information page. Under SSL, check whether SSL is enabled.
- If it is disabled, use a non-SSL connection.
- If it is enabled, use an SSL connection (recommended). SSL encrypts connections to the instance, making in-transit data more secure.
- Run the following command on the ECS to connect to the DB instance:
mysql -h host -P port -u userName -p
Example:
mysql -h 172.16.0.31 -P 3306 -u root -p
Table 1 Parameter description Parameter
Description
host
Private IP address of the DB instance.
port
Database port of the DB instance. The default value is 3306.
userName
Administrator account root.
- Enter the password of the database account if the following information is displayed:
Enter password:
Figure 10 Successful connection
- On the Instances page, click the instance name to go to the Basic Information page.
- Click Download under SSL to download Certificate Download.zip, and extract the root certificate ca.pem and bundle ca-bundle.pem from the package.
- Upload ca.pem to the ECS. It is recommended that the root certificate be stored in the same directory as the MySQL client installation package.
- Run the following command on the ECS to connect to the DB instance:
mysql -h host -P port -u userName -p --ssl-ca=caName
Example:
mysql -h 192.168.0.79 -P 3306 -u root -p --ssl-ca=ca.pem
Table 2 Parameter description Parameter
Description
host
Private IP address of the DB instance.
port
Database port of the DB instance. The default value is 3306.
userName
Administrator account root.
caName
Name of the CA certificate. The certificate should be stored in the directory where the command is executed.
- Enter the password of the database account if the following information is displayed:
Enter password:
Other Methods for Connecting to a DB Instance
FAQs
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.
For any further questions, feel free to contact us through the chatbot.
Chatbot