All Products
Search
Document Center

:"Too many connections" error reported in MySQL

Last Updated:Feb 08, 2021

Issue

After you connect to the MySQL database through the client, the database returns the following message.

Too many connections

Cause

The possible causes are listed as follows:

  • The database performance does not meet business requirements.
  • If the code is defective, it may cause a large number of connections.

Solutions

Method 1: adjust the maximum number of connections or sleep time of the database

  • Adjust the maximum number of connections
    1. Use the root user in the database and execute the following SQL statement to view the current number of all threads:
      show full processlist;
    2. If the number of threads is large or greater than the maximum number of connections of the current instance type, you can upgrade the instance configuration to increase the maximum number of connections to the database based on the actual business scenario. For more information about upgrading an instance, see change specifications.
      Note:
  • Adjust sleep time
    You can adjust the wait_timeout parameter for connecting to the database by referring to set instance parameters. Depending on the business scenario requirements, if the wait_timeout parameter is large, you can change the wait_timeout parameter to a smaller value.

Method 2: Locate the error message log locate the problem.

  1. In the database, execute the following SQL statement to view the log error information.
    show global variables like 'log_error';
  2. Based on the returned information, check the content of the log file in the corresponding directory to locate the problem based on the file content.

Method 3: Restart the services connected to the server

  1. If there is a local debugging or code defect in the Test environment, you can modify the code and restart the service connected to the database to release some connections.
  2. If this error still occurs after the service is restarted, contact the DBA of the corresponding business to terminate the server connection or restart the database. For more information about how to view the business DBA, see the following topics:
    1. Log on to the DMS console.
    2. in the left-side navigation pane, find the database you want to view. right-click the target instance and select instance DBA from the displayed list to view the DBA of the database.

Applicable scope

  • Data Management (DMS)