Updated on 2024-09-12 GMT+08:00

Connecting to a DB Instance Using a MariaDB Client

You can connect to an instance through a non-SSL connection or an SSL connection using a MariaDB client. SSL encrypts connections to your DB instance and is more secure.

Prerequisites

  1. An EIP has been bound to the target DB instance and security group rules have been configured. The operations are as follows:
    1. Bind an EIP to your DB instance.

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

    2. Obtain the IP address of the ECS you use to connect to the DB instance.
    3. Configure security group rules.

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

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

    4. Run the ping command to check the connectivity between the ECS 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.

    You can use a database client to connect to the target DB instance in Linux or Windows.

    • In Linux, you need to install a MariaDB client on your device. It is recommended that you download a MariaDB client running a version later than that of the DB instance.
    • In Windows, you can use any common database client to connect to the target DB instance in a similar way.

Connecting to a DB Instance Using Commands (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 Databases > Relational Database Service.
  4. On the Instances 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 OK. Then, go to 6.

  6. 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.
  7. Import the root certificate ca.pem to the Linux or Windows. For details, see How Can I Import the Root Certificate to a Windows or Linux OS?
  8. Connect to the RDS for MariaDB instance. In Linux, for example, run the following command:

    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 of the DB instance to be connected.

    <port>

    Port of the DB instance to be connected.

    <userName>

    Database account used for logging in to the DB instance. The default value is root.

    <caName>

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

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

    Enter password:
    Figure 1 Connection example

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