Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Using MySQL CLI to Connect to an Instance Through a Public Network

Updated on 2025-01-02 GMT+08:00

If you cannot access your DB instance through a floating IP address, bind an EIP to the DB instance and connect to it through the EIP.

This section describes how to connect a Linux ECS to a DB instance with SSL enabled through an EIP. SSL encrypts connections to the DB instance, making in-transit data more secure.

You can also access your DB instance through Network Address Translation (NAT). If you have configured both NAT and EIP, the EIP is preferentially used.

Step 1: Buy an ECS

  1. Log in to the management console and check whether there is an ECS available.
    • If there is a Linux ECS, go to 3.
    • If no ECS is available, go to 2.
    Figure 1 ECS
  2. 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.

    For details about how to purchase a Linux ECS, see Purchasing a Custom ECS in Elastic Cloud Server User Guide.

  3. On the ECS Information page, view the region and VPC of the ECS.
    Figure 2 ECS information
  4. On the Overview page of the RDS for MySQL instance, view the region and VPC of the DB instance.
    Figure 3 Overview

Step 2: Test Connectivity and Install the mysql Client

  1. Log in to the ECS. For details, see "Login Using an SSH Password" in the Elastic Cloud Server User Guide.
  2. On the Instances page of the RDS console, click the DB instance name.
  3. Choose Connectivity & Security from the navigation pane. In the Connection Information area, obtain the EIP and database port of the DB instance.
    Figure 4 Connection information

    If no EIP has been bound to the DB instance, see Binding an EIP.

  4. On the ECS, check whether the EIP and database port of the DB instance can be connected.

    Run the yum install telnet command to install the Telnet tool in advance.

    telnet EIP 3306

    • 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 EIP and port of the DB instance.
        Figure 5 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.
  5. Import the mysql client installation package to the ECS.

    Method 1:

    Download a mysql client installation package for Linux using the ECS. To do so, you need to bind an EIP to the ECS.
    • mysql 8.0:

      wget https://dev.mysql.com/get/mysql-community-client-8.0.28-1.el6.x86_64.rpm

    • mysql 5.7:

      wget https://dev.mysql.com/get/mysql-community-client-5.7.38-1.el6.x86_64.rpm

    NOTE:

    A mysql client running a version later than that of the DB instance is recommended.

    Method 2:

    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.

    • mysql 8.0:

      Click here to download an installation package. mysql-community-client-8.0.28-1.el6.x86_64.rpm is used as an example.

      Figure 6 Downloading a mysql 8.0 installation package
    • mysql 5.7:

      Click here to download an installation package. mysql-community-client-5.7.38-1.el6.x86_64.rpm is used as an example.

      Figure 7 Downloading a mysql 5.7 installation package
    NOTE:

    A mysql client running a version later than that of the DB instance is recommended.

  6. Run the following command to install the mysql client:
    • mysql 8.0:

      rpm -ivh --nodeps mysql-community-client-8.0.28-1.el6.x86_64.rpm

    • mysql 5.7:

      rpm -ivh --nodeps mysql-community-client-5.7.38-1.el6.x86_64.rpm

    NOTE:
    • 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

Step 3: Connect to the DB Instance Using Commands (SSL Connection)

  1. On the Instances page, click the DB instance name.
  2. In the Basic Information area, check whether SSL is enabled.
    • If yes, go to 3.
    • If no, click Enable. In the displayed dialog box, click OK to enable SSL. Then go to 3.
  3. Click next to the SSL field to download Certificate Download.zip, and extract the root certificate ca.pem and bundle ca-bundle.pem from the package.
  4. Upload ca.pem to the ECS.
    NOTE:
    • Since April 2017, RDS has offered a new root certificate that has a 20-year validation period. The new certificate takes effect after DB instances are rebooted. Replace the old certificate before it expires to improve system security.

      For details, see How Can I Identify the Validity Period of an SSL Root Certificate?

    • TLS v1.2 or later is recommended. Versions earlier than TLS v1.2 have security risks.
    • ca-bundle.pem contains both the new certificate provided as of April 2017 and the old certificate.
    • Both ca.pem and ca-bundle.pem can be used for SSL connections because ca-bundle.pem contains ca.pem.
    • RDS for MySQL DB instances do not support X.509-based authentication.
  5. 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 172.16.0.31 -P 3306 -u root -p --ssl-ca=ca.pem

    Table 1 Parameter description

    Parameter

    Description

    <host>

    EIP or public domain name obtained in 3.

    NOTE:

    To connect to a DB instance using a public domain name, apply for a public domain name first. For details, see Applying for and Changing a Public Domain Name.

    After a public domain name is generated, changing the EIP will interrupt database connections. Exercise caution when performing this operation.

    <port>

    Database port obtained in 3. 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.

  6. Enter the password of the database account if the following information is displayed:
    Enter password:

Follow-up Operations

After logging in to the DB instance, you can create or migrate databases.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback