Using MySQL CLI to Connect to an Instance Through a Public Network
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 or disabled through an EIP. SSL encrypts connections to the DB instance, making in-transit data more secure.
Prerequisites
- You have bound an EIP to the target DB instance and configured security group rules.
- Bind an EIP to the target DB instance.
- Obtain the IP address of the ECS you use to connect to the DB instance.
- Configure security group rules.
Add the IP address obtained in 1.b and the instance port to the inbound rule of the security group.
- Run the ping command to ping the EIP bound in 1.a to ensure that the EIP is accessible through the ECS.
- You have installed a database client to connect to DB instances.
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.
Connecting to a DB Instance Using Commands (SSL Connection)
- Log in to the management console.
- Click in the upper left corner of the page and choose Databases > Relational Database Service.
- On the Instances page, click the instance name to go to the Basic Information page.
- In the DB Information area, check whether SSL is enabled.
- 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.
- Import the root certificate ca.pem to the Linux or Windows.
- 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.pemTable 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 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.
- 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 all prerequisites are correctly configured and try again.
Connecting to a DB Instance Using Commands (Non-SSL Connection)
- Log in to the management console.
- Click in the upper left corner of the page and choose Databases > Relational Database Service.
- On the Instances page, click the instance name to go to the Basic Information page.
- In the DB Information area, check whether SSL is enabled.
- Connect to the DB instance. In Linux, for example, run the following command:
mysql -h <host> -P <port> -u <userName> -p
Example:
mysql -h 172.16.0.31 -P 3306 -u root -p
Table 2 Parameter description Parameter
Description
<host>
of the DB instance to be connected.
<port>
Port of the DB instance to be connected.
<userName>
Username of the database account. The default administrator is root.
- Enter the password of the database account if the following information is displayed:
Enter password:
Figure 2 Non-SSL connection example
If the connection fails, ensure that preparations have been correctly made in Prerequisites and try again.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.