All Products
Search
Document Center

:How do I terminate sessions on an ApsaraDB RDS for MySQL instance?

Last Updated:Jan 15, 2025

Overview

This topic describes how to terminate sessions on an ApsaraDB RDS for MySQL instance.

Procedure

You can terminate sessions on an RDS instance by using one of the following methods:

  • Use the session management feature.

  • Use the kill command.

Important

A privileged account can terminate all sessions. A standard account can terminate only the current session. For more information about account permissions, see Account types.

Use the session management feature to terminate sessions

  1. Log on to the ApsaraDB RDS console. In the top navigation bar, select a region in which your RDS instance resides. Find the RDS instance and click the instance ID.

  2. In the left-side navigation pane of the page that appears, choose Autonomy Services > Diagnostics.

  3. Click the Session Management tab.

  4. On the Session Management tab, view the information about the current sessions of the RDS instance and terminate unnecessary sessions by using the session termination feature. For more information, see Use the session management feature.

    image

Use the kill command to terminate sessions

  1. Connect to the RDS instance by using the MySQL command-line tool. For more information, see Use a client or the CLI to connect to an ApsaraDB RDS for MySQL instance.

    Note

    If the number of connections to the RDS instance reaches the upper limit, you cannot connect to the RDS instance by using Data Management (DMS) or the MySQL command-line tool. In this case, we recommend that you terminate sessions by using the session management feature.

  2. Execute the following statement to query current sessions and record the ID of the session that you want to terminate:

    SHOW processlist;

    The following sample output is returned.Viewing sessions via command line

  3. Run the following command to terminate the session:

    KILL [$ID];
    Note

    [$ID] specifies the ID of the session that you want to delete.

    The following sample output is returned. Terminating a session via command line

What to do next

You can modify the wait_timeout and interactive_timeout parameters to optimize the timeout period for an RDS instance to automatically terminate connections. For more information, see Modify instance parameters.

Important

The modification of the parameters only affects new sessions.

  • For connections in non-interactive mode, log on to the ApsaraDB RDS console and decrease the value of the wait_timeout parameter on the Parameters page. The wait_timeout parameter specifies the timeout period of a connection in non-interactive mode. Default value: 86400. Unit: seconds. The default value equals 24 hours. When a non-interactive connection is idle for a period of time that is longer than the value of the wait_timeout parameter, the RDS instance automatically terminates the connection.

  • For connections in interactive mode, log on to the ApsaraDB RDS console and decrease the value of the interactive_timeout parameter on the Parameters page. The interactive_timeout parameter specifies the timeout period of a connection in interactive mode. Default value: 7200. Unit: seconds. The default value equals 2 hours. When an interactive connection is idle for a period of time that is longer than the value of the interactive_timeout parameter, the RDS instance automatically terminates the connection.

Application scope

  • ApsaraDB RDS for MySQL