Help Center > > Getting Started> Getting Started with RDS for MySQL> Connecting to a DB Instance Through a Public Network> Step 4: Connect to a DB Instance Through a Public Network

Step 4: Connect to a DB Instance Through a Public Network

Updated at: May 26, 2020 GMT+08:00

You can connect to a DB instance through a common connection or an SSL connection. The SSL connection encrypts data and is more secure.

Preparations

  1. Bind an EIP to the target DB instance and configure security group rules.
    1. Bind an EIP to the target DB instance.

      For details about how to bind an EIP, see section Step 2: Bind an EIP.

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

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

      For details about how to configure a security group rule, see section Step 3: Configure Security Group Rules.

    4. Run the ping command to connect the EIP that has been bound to the target DB instance in 1.a to check that the local device can connect to the EIP.
  2. Use a database client to connect to the target DB instance.

    You can use a database client to connect to the target DB instance in the Linux or Windows operating system (OS).

    • 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 about how to obtain and install the MySQL client, see How Can I Install the MySQL Client?

Using MySQL-Front to Connect to a DB Instance

  1. Start MySQL-Front.
  2. In the displayed dialog box, click New.

    Figure 1 Connection management

  3. Enter the information of the target DB instance to be connected and click Ok, as shown in Figure 2.

    Figure 2 Adding an account
    Table 1 Parameter description

    Parameter

    Description

    Name

    Indicates the name of the database connection task. If you do not set this parameter, it will be the same as Host by default.

    Host

    Indicates the EIP of the DB instance to be connected.

    Port

    Indicates the private network port of the DB instance.

    User

    Indicates the name of the user who will access the DB instance. The default user is root.

    Password

    Indicates the password of the RDS database account.

  4. In the displayed window, select the connection that you have created in Figure 3 and click Open.

    If the connection information is correct, the DB instance is successfully connected.
    Figure 3 Opening a session

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

Using SSL to Connect to a DB Instance

  1. Log in to the management console.
  2. Click in the upper left corner and select a region and a project.
  3. Click Service List. Under Database, click RDS. The RDS console is displayed.
  4. In the DB Information area on the Basic Information page, click in the SSL field to download the root certificate or certificate bundle.
  5. 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 the SSL Root Certificate?

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

  6. Run the following command to connect to an RDS DB instance. The Linux OS is used as an example.

    mysql -h < hostName> -P <port> -u < userName> -p --ssl-ca=< caName>
    Table 2 Parameter description

    Parameter

    Description

    <hostName>

    Indicates the EIP of the DB instance to be connected.

    <port>

    Indicates the port of the DB instance to be connected.

    <userName>

    Indicates the username of the RDS database account. The default administrator is root.

    <caName>

    Indicates the name of the SSL certificate file, which should be stored in the same 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 Preparations and try again.

Did you find this page helpful?

Submit successfully!

Thank you for your feedback. Your feedback helps make our documentation better.

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