Relational Database Service (MySQL)

Database Instance Connection

2025-06-04 01:02:04

What should I do if RDS for MySQL instance fails to be connected?

In general, you can troubleshoot the RDS for MySQL instance connection failure from the following aspects:

1. Check whether the database instance is normal.

First, check whether the database instance is normal. You can view the instance status on the console. If the instance is unavailable due to arrears, expiration, or other reasons, the client may not be connected to the instance.

2. Check whether the client connection is correct.

The client connection issue is a common reason for the instance connection failure. For details, see the description of the two connection methods Connecting to a MySQL Instance Through an Intranet and Connecting to a MySQL instance Through a Public Network in Quick Start. In summary, pay attention to the following:

• If the instance is connected through an Intranet, the database instance and the cloud server instance must be in the same resource pool and the same VPC.

• If the instance is connected through a public network, you need to purchase or use an elastic IP (EIP), and bind the EIP to the destination database instance.

3. Check whether the SSL connection is correct.

If SSL is enabled on the Console, you need to check whether the SSL connection is correctly. For example, when a command line is used for connection at the terminal:

• The switch is enabled and the SSL connection is mandatory: mysql -h 192.168.X.X -P 3306 -u root -p --ssl-ca=/path/to/ca.pem.

• The switch is enabled and the SSL connection is not mandatory: mysql -h 192.168.X.X -P 3306 -u root -p.

4. Check whether the connection command is correct.

The connection commands or information on the client interface may be incorrect. These errors may include connection address, connection port, user name, and corresponding password errors. Please double-check and make sure that the information entered is accurate.

5. Check whether the network is available.

Intranet access:

• Make sure that the ECS and the database instance are in the same region and VPC.

• Check the security group rules. Different security groups require different inbound/outbound rules. For details, see Configuring Security Group Rules.

Public network access:

• Check the EIP. The EIP is a separate product. You need to check if the EIP is normal and whether it is properly bound on the database instance host.

• Check security group rules. You need to add the corresponding rules for the database instance. For details, see Configuring Security Group Rules.

6. Check whether the number of connections to the instance reaches the upper limit.

An excessive number of database connections to the database instance may also cause the application to be unable to establish new connections. To avoid this issue, it is recommended that you optimize and limit the number of connections to ensure that the database can handle and respond to all required connection requests. This can be realized by adjusting the database connection pool size, optimizing service logic, or increasing the number of database instances.

7. Check the host resources.

When the host resources, such as disk, CPU, memory, etc. reach the upper limit, it will directly affect the connection and normal reading and writing of database instances. To avoid this, it is recommended that you monitor the use of host resources and optimize and expand resources as needed so that the database instance can function properly and process requests. For details, see User Guide-Monitoring and Alarms-Configuring Custom Alarm Rules.

Can an external server access an RDS for MySQL instance?

You can access our database instance in the following two ways:

• Public network access: For a database instance that has an elastic IP (EIP), you can directly access it through an external network. For details, see Connecting to a MySQL Instance Through a Public Network in Quick Start.

• Intranet access: Alternatively, you can access the database instance through an Intranet. You only need to create an RDS for MySQL instance and the ECS under the same VPC subnet and directly access the database instance through the cloud server. For details, see Connecting to a MySQL Instance Through an Intranet in Quick Start.

What should I do if the number of RDS for MySQL instance connections reaches the upper limit?

When the number of connections reaches the upper limit, the instance may not be connected:

An excessive number of idle connections may be caused by the following reasons:

Long connection mode: A connection pool is configured on the client service, and the initial number of connections in the connection pool is set too high. After the application starts, multiple idle connections to MySQL instances are established.

Short connection mode: For the client service code, the connection is not explicitly closed after the query is completed.

 Solution:

Use the kill command directly to terminate the session connection.

For the long connection, you need to enable the multiplexing function of the connection pool (it is recommended to reduce the initial number of connections). For the short connection, you need to check whether there are missing connections in the service code.

For non-interactive mode connections, set the wait_timeout parameter (which controls the timeout time for non-interactive mode connections) to a small value in the Parameter Setting of the Console.

For interactive mode connections, set the interactive_timeout (which controls the timeout time for interactive mode connections) parameter to a small value in the Parameter Setting of the Console.

An excessive number of active connections may be caused by the following reasons:

The increase in slow query of SQL statements results in the accumulation of active connections.

Lock waits result in the accumulation of active connections (including InnoDB lock waits, table metadata lock waits, etc).

Excessive usage of CPU and IOPS leads to the accumulation of active connections.

 Solution:

Check the execution of slow SQL statements, and optimize SQL according to the scenario.

Upgrade instance specifications or extend read-only instances.

What is the maximum number of data connections to an RDS for MySQL database instance?

By default, the maximum number of data connections to a database instance is 3000. You can view the maximum number of connections set for the current instance by using the following command:

show global variables like 'max_connections';

If you need to adjust the maximum number of data connections, you can use the database instance parameter max_connections. For details, see Modifying the Parameter Group.


How do I create and connect an ECS?

• For details about how to create an ECS, see Creating an ECS.

• For details about how to connect an ECS, see Logging in to an ECS.

It should be noted that when accessing an RDS for MySQL instance through an ECS, there are no restrictions on the creation of an ECS, such as a network or security group if the connection is realized through a public network. If the connection is realized through an Intranet, make sure that the activated cloud server and database instance are in the same VPC. In addition, note the security group rule settings. For details, see Configuring Security Group Rules.

What should I do if an ECS cannot connect to an RDS for MySQL instance through an Intranet?

If an ECS cannot connect to an RDS for MySQL instance through an Intranet, you can troubleshoot from the following aspects:

• Check whether the database password used during the connection is correct. You can reset the password through the Database Console interface.

• Check whether the MySQL Console interface instance is abnormal.

• Check whether the VPC to which the database instance belongs and the ECS are the same VPC subnet.

• If they belong to different security group rules, check if the security group is released.

What should I do if a client problem causes a connection failure?

Troubleshoot the RDS for MySQL connection failures caused by a client problem by checking the following items:

• ECS Security Policy: For Windows platforms, check whether the database instance port is enabled in the Windows security policy. For Linux platforms, use iptables to check the firewall and port release.

• Client Application Configuration Error: Common errors include connection address errors, port errors, user name errors, user password errors, and connection errors. If you use JDBC and other API configurations, there may be errors with the connection parameter configurations.

Some common client configuration errors are reported as follows:

Error Message

Common Causes

[Warning] Access denied for user 'username'@'yourIp' (using password: NO)

The password is not filled in.

[Warning] Access denied for user 'username'@'yourIp' (using password: YES)

The password or username is incorrect.

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'

The connection method is incorrect.

What should I do if an application problem causes a connection failure?

Troubleshoot the RDS for MySQL connection failures caused by an application problem by checking the following items:

• Whether the connection method is incorrect: When the database instance is connected through an Intranet, the ECS and the database instance must be in the same virtual private cloud (VPC), otherwise, they cannot be connected through an Intranet. There are no such restrictions when the instance is connected through a public network.

• Whether the number of connections reaches the upper limit: If the number of connections reaches the upper limit of the database instance, the database instance cannot establish a new connection with the client, resulting in a connection error.

• Whether the instance is abnormal: If the instance is in abnormal status, such as when the instance restarts, the instance or table is locked, the host system fails, the network fails, etc., the database instance cannot be connected.

How does an application access an RDS for MySQL instance in a VPC?

The RDS for MySQL instance can be accessed in two ways: Intranet access and public network access.

Connection Method

IP Address

Usage Scenarios

Description

Intranet connection

Intranet IP Address

The system provides an Intranet IP address by default.

When your application is deployed on an ECS that is in the same region and VPC as the MySQL instance, you are advised to use the Intranet IP to connect the ECS to the relational database instance separately.

High security and better performance of MySQL.

An Intranet connection is recommended.

Public network connection

EIP

When the RDS for MySQL instance cannot be accessed through an Intranet IP address, use the public network access. It is recommended to bind the EIP separately to connect the ECS (or the public network host) to the RDS for MySQL instance.

Direct access to the public network with good flexibility. Lower level of security compared to the Intranet connection.

An Intranet connection is recommended.

You can select the appropriate connection method according to your actual needs. For details, see Introduction to Instance Connection Mode in Quick Start.

Do applications need to support automatic reconnection to databases?

It is recommended that your application support automatic reconnection of the database. In addition, use the long connection method to connect to the database to reduce resource consumption and improve database performance. When the database is restarted, manual intervention is not required. The application automatically restores the database connection, thus ensuring a higher availability and better fault tolerance of the application.

Why cannot I ping my public network IP after it is bound to an instance?

Check security group rules. On theNetwork Console-Security Groups page, find the security group that belongs to the destination database instance and check the inbound rules.

Check the Network ACL rule.

Ping the affected IP from another ECS in the same region. Use another ECS in the same region to ping the EIP. If the EIP can be pinged, the virtual network is normal. If the EIP cannot be pinged, contact technical support.

How can I obtain a local IP address?

The EIP of the user is not fixed, and the IP address located by the local IP address viewing tool is inaccurate. Even if the queried local IP is added to the trustlist of RDS for MySQL instance, it cannot be connected to the database instance. In addition to viewing the local IP address through a Website query, etc., you can locate the local IP address through a database instance following the steps below:

Add the IP address or IP segment that is allowed to access the instance to the trustlist of RDS for MySQL instance.

Use the MySQL client to connect to a database instance:

mysql -h host_name -P port -u username -p

If Enter password is promoted, enter the password.

Check the process information: SHOW PROCESSLIST; As shown in the figure below, host is the corresponding local exit IP.

 

If the SQL audit log has been enabled, you can view the historical connection sources of the database through the audit log. However, if this function is not enabled before, the history records cannot be queried. The SQL audit log starts logging after it is enabled.

Can I access an RDS for MySQL instance over an Intranet connection across regions?

By default, RDS for MySQL instances cannot be accessed over an Intranet across regions because the Intranets in different regions cannot communicate with each other. However, the instance can still be accessed through a public network.

• Elastic IP (EIP): When an RDS for MySQL instance cannot be accessed through the IP address of an Intranet, it can be accessed through the IP address of a public network. For details, see Connecting to a MySQL Instance Through a Public Network.

• Peering Connection and Virtual Private Network (VPN): VPCs in different regions are interconnected to realize global network connections on the cloud across regions. For details, see VPC Connection.

Does the master-slave switching affect an SSL connection to a database?

The SSL certificate for the database is valid for both the Master and Slave. Even when a master-slave switching occurs, database connection through SSL is not affected. When the database is switched from the Master to the Slave, the data transmission and communication through the SSL connection are not affected by the client.

Will my access be restricted by bandwidth when I connect to a database through an ECS Intranet?

No, the access to the database through an ECS Intranet is not restricted by bandwidth. Compared with public network access, Intranet access is not restricted by bandwidth and has lower latency. Access to the database through the Internet is recommended, which can improve the performance and efficiency of database access and ensure better user experience and data transmission quality.

Why did the new password not take effect after I reset the password?

A possible cause is that you may have restored from a backup before you reset the password. It is recommended that you check whether the restoration operation has been performed after a password reset. You can also reset the password on the console. For details, see User Guide-Instance Management-Modifying the Instance Password.

How do I set the encoding format of the MySQL 8.0 character set?

You can set the database encoding format by setting the relevant parameters. Set the parameters based on the following list:

character_set_server=utf8

collation_server=utf8_general_ci


For details, see User Guide-Parameter Management-Modifying the Parameter Group..

What should I do if the ECS and database are deployed in different VPCs and cannot communicate with each other?

You can switch the VPC of the ECS to the same VPC as the database. For details, see Virtual Private Cloud-VPC Management-Modifying the Virtual Private Cloud.

Create a peering connection for two different VPCs to realize Intranet interoperability. For details, see Creating a Peering Connection-Applying for a Peering Connection (With the Same Account).

How do I view all the current IPs connected to a database?

You can log in to the database with an administrator account and execute the following SQL statement on the database to count the number of connected IPs.

SELECT substring_index(host, ':',1) AS host_name,state,count(*) FROM information_schema.processlist GROUP BY state,host_name;

Can I access the standby instance of a database directly?

No. The eSurfing Cloud RDS for MySQL supports the primary instances, backup instances, and read-only instances. Among them, primary instances and read-only instances can be directly accessed, while the backup instances cannot.

The standby instance supports switching with the primary instance. After switching, the original standby instance becomes the primary instance, and the data of the primary/standby instances will be synchronized in real time.

How do I view the connections to an RDS for MySQL instance?

You can log in to the database instance with an administrator account and execute the show full processlist command to see the current connection:

 

Here are the descriptions of relevant parameters:

• Id: The thread ID. The statement can be terminated by the kill id command.

• User: The user connected to the current thread.

• Host: The port on which IP the connection originated from.

• db: Database name.

• Command: Connection status, usually including sleep, query, and connect.

• Time: Connection duration, in seconds.

• State: The status of the current SQL statement.

• Info: The currently executed SQL statement.


D9UoS4cKN0pC