Connecting to a DB Instance over a Private Network
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.
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.
- Buy an ECS and select Linux (for example, CentOS) 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 DB instance for mutual communications.
For details about how to create a Linux ECS, see section "Creating an ECS" in Elastic Cloud Server User Guide.
- On the ECS Information page, view the region and VPC of the ECS.
- 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, create 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 section "Changing a VPC" in Elastic Cloud Server User Guide.
Step 2: Test Connectivity and Install the mysql Client
- Log in to the ECS. For details, see section "Logging In to a Linux ECS Using VNC" in Elastic Cloud Server User Guide.
- On the Instances page of the TaurusDB console, click the instance name to go the Basic Information page.
- In the 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.
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 yes, network connectivity is normal.
- 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 an outbound rule for the private IP address and port of the DB instance.
- 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 Security Group Rules.
- Download the mysql client installation package for Linux locally. A mysql client running a version later than that of the DB instance is recommended.
Find the link to the required version on the download page. The mysql-community-client-8.0.21-1.el6.x86_64 is used as an example.
Figure 1 Downloading a mysql client - Upload the installation package to the ECS.
- Use any terminal connection tool, such as WinSCP and PuTTY, to upload the installation package to the ECS.
- Run the following command to install the mysql client:
rpm -ivh 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
- 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 Commands (SSL Connection)
- On the Instances page of the TaurusDB console, click the instance name to go the Basic Information page.
- In the DB Instance Information area, check whether SSL is enabled.
- Click
under SSL to download Certificate Download.zip, and obtain the root certificate ca.pem and bundle ca-bundle.pem from the package.
- Upload ca.pem to the ECS.
- 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 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.
<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:
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.