This topic describes the steps to configure connection persistence for an RDS for MySQL instance.
When you use RDS for MySQL, performing a switchover operation on an instance causes a brief interruption in the connection between the application and the database proxy. This can impact your business. To address this, RDS for MySQL provides the connection persistence feature, which ensures stable connections, improves product availability, and reduces operation costs.
- The connection persistence feature cannot maintain connections when prepare is enabled.
- The connection persistence feature cannot maintain connections when you restart the entire instance, which means the restart scope is set to All nodes.
tip
For multiple-node instances, selecting a restart scope is not supported. You can only restart the entire instance.
- The connection persistence feature will take effect within 10 minutes when it is enabled or diabled.
- Connections for which the MySQL server has not completely returned data packets. For example, for a 100 MB result set, only 50 MB has been returned, and the remaining result set is still being transmitted.
- Uncommitted transactions exist.
- Unparsed statements have been used on the connection.
- LOAD DATA statements have been used on the connection.
- Temporary collections exist.
- Connections that subscribe to Binlog through the database proxy address.
- Calls to the FOUND_ROWS, ROW_COUNT, and LAST_INSERT_ID functions are not supported. Although these functions can be called successfully, the accuracy of the results cannot be guaranteed. SELECT FOUND_ROWS() has been deprecated by MySQL. It is recommended to replace SELECT FOUND_ROWS() with SELECT COUNT(*) FROM tb1 for queries. For details, refer to FOUND_ROWS().
- Because connections may reconnect, the thread ID of the current connection returned by SELECT CONNECTION_ID() may change.
- Because connections are re-established, the Internet protocol address and port displayed in SHOW PROCESSLIST or SQL Insight may not match those of the client.
- If a connection contains user-defined variables, the connection can be maintained, but the variables will become invalid.
- An instance has been created, and its state is Running. For more details, refer to Creating an instance.
- The database proxy feature is enabled for the instance. For details about enabling the database proxy, refer to Enable database proxy.
- In the upper-left corner of the top menu bar, select the project and region for the instance.
tip
If the project of the instance has not been set, the project should be selected as All resources.
- In the left navigation bar, choose MySQL > Instances.
- On the Instances page, click the target instance name.
- Click the Connectivity tab at the top of the page.
- On the Connectivity page, in the Endpoints list, click Edit in the Actions column for the target connection endpoint to open the Modify endpoint page.
- On the Modify endpoint page, enable or disable connection persistence, and then click OK.
This topic only tests the active switchover scenario.
- The MySQL instance for the test is as follows:
- MySQL 8.0 version, High-availability architecture.
- The instance specification is 8-core 16 GB dedicated type (rds.mysql.d1.8c16g).
- The test data is as follows:
- 100 tables, each with 40,000 rows of data.
- The number of concurrent threads is 128.
In different operation scenarios, test the connection persistence rate of the MySQL instance (the ratio of connections maintained before and after the operation).
Execute test statement:
Parameter description
The parameters in the statement are described as follows:
- db-driver: database engine, the value must be mysql.
- mysql-host: the database proxy address, which must be replaced with your actual value.
- tables: the number of tables in the database.
- table-size: the number of records in each table.
- threads: the number of concurrent threads.
- time: the test time is measured in seconds.
The test results are as follows.
In the following tested operation scenarios, the MySQL instance maintains a 100% connection persistence rate.