Relational Database ServiceRelational Database Service

Compute
Elastic Cloud Server
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
Domain Name Service
VPC Endpoint
Cloud Connect
Enterprise Switch
Security & Compliance
Anti-DDoS
Web Application Firewall
Host Security Service
Data Encryption Workshop
Database Security Service
Advanced Anti-DDoS
Data Security Center
Container Guard Service
Situation Awareness
Managed Threat Detection
Compass
Cloud Certificate Manager
Anti-DDoS Service
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GaussDB NoSQL
GaussDB(for MySQL)
Distributed Database Middleware
GaussDB(for openGauss)
Developer Services
ServiceStage
Distributed Cache Service
Simple Message Notification
Application Performance Management
Application Operations Management
Blockchain Service
API Gateway
Cloud Performance Test Service
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
DevCloud
ProjectMan
CodeHub
CloudRelease
CloudPipeline
CloudBuild
CloudDeploy
Cloud Communications
Message & SMS
Cloud Ecosystem
Marketplace
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP License Service
Support Plans
Customer Operation Capabilities
Partner Support Plans
Professional Services
enterprise-collaboration
Meeting
IoT
IoT
Intelligent EdgeFabric
DeveloperTools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Updated at: Apr 02, 2022 GMT+08:00

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

You can connect to an instance through a non-SSL connection or an SSL connection using the MySQL client. The SSL connection encrypts data and is more secure.

Prerequisites

  1. An EIP has been bound to the target DB instance and security group rules have been configured.
    1. Bind an EIP to the target DB instance.

      For details about how to bind an EIP, see Binding an EIP.

    2. Obtain the IP address of the local device.
    3. Configure security group rules.

      Add the IP address obtained in 1.b and the instance port to the inbound rule of the security group.

      For details about how to configure security group rules, see Configuring Security Group Rules.

    4. Run the ping command to check the connectivity between the local device and the EIP that has been bound to the DB instance in 1.a.
  2. You have installed a database client to connect to DB instances.

    In the Linux OS, you need to install a MySQL client on the ECS. It is recommended that you download a MySQL client running a version later than that of the DB instance.

    For details, see Installing the MySQL Client.

SSL Connection

  1. Log in to the management console.
  2. Click in the upper left corner and select a region and a project.
  3. Click in the upper left corner of the page and choose Database > Relational Database Service. The RDS console is displayed.
  4. On the Instance Management page, click the instance name to go to the Basic Information page.
  5. In the DB Information area, check whether SSL is enabled.

    • If yes, go to 6.
    • If no, click . In the displayed dialog box, click Yes. Then go to 6.

  6. Click next to SSL to download the root certificate or certificate bundle.
  7. Import the root certificate to the Linux OS on the ECS. For details, see How Can I Import the Root Certificate to the Windows or Linux OS?

    • 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?

    • You can also download the certificate bundle, which contains both the new certificate provided since April 2017 and the old certificate.

  8. Connect to the RDS DB instance. The Linux OS is used as an example.

    mysql -h <host>-P <port>-u <userName>-p--ssl-ca=<caDIR>
    Table 1 Parameter description

    Parameter

    Description

    <host>

    EIP of the DB instance to be connected.

    <port>

    Port of the DB instance to be connected.

    <userName>

    Username of the RDS database account. The default administrator is root.

    <caDIR>

    Directory of the CA certificate. The certificate should be stored in the directory where the command is executed.

    For example, to connect to a DB instance through an SSL connection as user root, run the following command:

    mysql -h 172.16.0.31 -P 3306 -u root -p --ssl-ca=ca.pem

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

    Enter password:

    If the connection fails, ensure that preparations have been correctly made in Prerequisites and try again.

Did you find this page helpful?

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel