- What's New
- Function Overview
- Product Bulletin
- Service Overview
- Billing
-
Getting Started
- Getting Started with RDS for MySQL
- Getting Started with RDS for MariaDB
- Getting Started with RDS for PostgreSQL
- Change History
- Kernels
-
User Guide
-
Working with RDS for MySQL
- Database Usage
- Database Migration
- Version Upgrade
-
Instance Management
- Instance Lifecycle
-
Instance Modifications
- Changing a DB Instance Name
- Changing a DB Instance Description
- Changing the Replication Mode
- Changing the Failover Priority
- Changing Read/Write Permissions
- Changing a DB Instance Class
- Scaling Up Storage Space
- Configuring Storage Autoscaling
- Changing the Maintenance Window
- Changing a DB Instance Type from Single to Primary/Standby
- Promoting a Read Replica to Primary
- Manually Switching Between Primary and Standby DB Instances
- Changing the AZ of a Standby DB Instance
- Data Backups
- Data Restorations
- Read Replicas
- Viewing and Changing a Floating IP Address
- Binding and Unbinding an EIP
- Changing a Database Port
- Applying for and Changing a Private Domain Name
- Configuring a Security Group Rule
-
Database Proxy (Read/Write Splitting)
- Introduction to RDS for MySQL Database Proxies
- Constraints on Database Proxy
- Using RDS for MySQL Database Proxies for Read/Write Splitting
-
Database Proxy Configurations
- Configuring Transaction Splitting
- Configuring Connection Pools
- Modifying Read/Write Splitting Parameters
- Configuring the Delay Threshold and Routing Policy
- Enabling or Disabling Access Control
- Changing the Read/Write Splitting Address
- Changing the Read/Write Splitting Port
- Changing the Number of Proxy Nodes
- Changing the Instance Class of a DB Proxy Instance
- Configuring Multi-Statement Processing Modes
- Changing a Proxy from Pay-per-Use to Yearly/Monthly
- Database Proxy Lifecycle
- Database Proxy Kernel Versions
- Best Practices for Database Proxy
- Problem Diagnosis and SQL Analysis
- Security and Encryption
-
Parameters
- Modifying Parameters of an RDS for MySQL Instance
-
Managing Parameter Templates
- Creating a Parameter Template
- Exporting a Parameter Template
- Comparing Parameter Templates
- Viewing Parameter Change History
- Replicating a Parameter Template
- Resetting a Parameter Template
- Applying a Parameter Template
- Viewing Application Records of a Parameter Template
- Modifying a Parameter Template Description
- Deleting a Parameter Template
- Suggestions on RDS for MySQL Parameter Tuning
- Log Management
- Metrics
- Interconnection with CTS
- Task Center
- RDS for MySQL Tags
-
Working with RDS for MariaDB
- Suggestions on Using RDS for MariaDB
- Instance Connection
- Parameter Tuning
- Instance Lifecycle
- Instance Modifications
- Read Replicas
- Data Backups
- Data Restorations
-
Parameter Templates
- Creating a Parameter Template
- Modifying RDS for MariaDB Instance Parameters
- Exporting a Parameter Template
- Importing a Parameter Template
- Comparing Parameter Templates
- Viewing Parameter Change History
- Replicating a Parameter Template
- Resetting a Parameter Template
- Applying a Parameter Template
- Viewing Application Records of a Parameter Template
- Modifying a Parameter Template Description
- Deleting a Parameter Template
- Connection Management
- Database Management
- Account Management (Non-Administrator)
- Account and Network Security
- Metrics
- Interconnection with CTS
- Log Management
- Task Center
- Managing Tags
-
Working with RDS for PostgreSQL
- Database Usage
- Database Migration
- Common Performance Problems
- Instance Lifecycle
-
Instance Modifications
- Upgrading a Minor Version
- Changing a DB Instance Name
- Changing a DB Instance Description
- Changing the Replication Mode
- Changing the Failover Priority
- Changing a DB Instance Class
- Scaling Storage Space
- Changing the Maintenance Window
- Changing a DB Instance Type from Single to Primary/Standby
- Manually Switching Between Primary and Standby DB Instances
- Changing the AZ of a Standby DB Instance
- Read Replicas
- Data Backups
- Data Restorations
-
Parameters
- Modifying Parameters of an RDS for PostgreSQL Instance
-
Managing Parameter Templates
- Creating a Parameter Template
- Exporting a Parameter Template
- Comparing Parameter Templates
- Viewing Parameter Change History
- Replicating a Parameter Template
- Resetting a Parameter Template
- Applying a Parameter Template
- Viewing Application Records of a Parameter Template
- Modifying a Parameter Template Description
- Deleting a Parameter Template
- Suggestions on RDS for PostgreSQL Parameter Tuning
- Connection Management
- Extension Management
- Tablespace Management
- Security and Encryption
- Metrics
- Interconnection with CTS
- Log Management
- Task Center
- Major Version Upgrade
- RDS for PostgreSQL Tags
-
Working with RDS for MySQL
- Best Practices
- Performance White Paper
-
API Reference
- Before You Start
- API Overview
- Calling APIs
- API v3.1 (Recommended)
-
API v3 (Recommended)
- Querying Version Information About APIs
- Querying Version Information About a DB Engine
- Querying Database Specifications
- Querying the Storage Type of a Database
-
DB Instance Management
- Creating a DB Instance
- Stopping an Instance
- Changing a DB Instance Name
- Changing the Description of a DB Instance
- Changing DB Instance Specifications
- Scaling Up Storage Space of a DB Instance
- Changing a Single DB Instance to Primary/Standby DB Instances
- Rebooting a DB Instance
- Deleting a DB Instance
- Querying DB Instances
- Binding and Unbinding an EIP
- Changing the Failover Priority
- Manually Switching Primary/Standby DB Instances
- Changing the Data Replication Mode of Primary/Standby DB Instances
- Configuring the Maintenance Window
- Database Security
- Backup and Restoration
- Log Information Queries
-
Database and Account Management (MySQL)
- Creating a Database
- Querying Details About a Database
- Querying Databases
- Querying Authorized Databases of a Specified User
- Deleting a Database
- Creating a Database Account
- Querying Database Users
- Querying Authorized Users of a Specified Database
- Deleting a Database Account
- Configuring a Password for a Database Account
- Authorizing a Database Account
- Revoking Permissions of a Database Account
- Resetting the Password for User root
- Database and Account Management (PostgreSQL)
-
Parameter Management
- Obtaining a Parameter Template List
- Creating a Parameter Template
- Modifying a Parameter Template
- Applying a Parameter Template
- Modifying Parameters of a Specified DB Instance
- Obtaining the Parameter Template of a Specified DB Instance
- Obtaining Parameters in a Specified Parameter Template
- Deleting a Parameter Template
- Recycling a DB Instance
- Tag Management
- Obtaining Task Information
- Appendix
- Change History
- SDK Reference
-
FAQs
- Product Consulting
- Resource and Disk Management
-
Database Connection
- What Should I Do If I Can't Connect to My RDS DB Instance?
- Can an External Server Access the RDS Database?
- What Do I Do If the Number of RDS Database Connections Reaches the Upper Limit?
- What Is the Maximum Number of Connections to an RDS DB Instance?
- How Can I Create and Connect to an ECS?
- What Should I Do If an ECS Cannot Connect to an RDS DB Instance Through a Private Network?
- What Should I Do If a Database Client Problem Causes a Connection Failure?
- What Should I Do If an RDS Database Problem Causes a Connection Failure?
- How Do My Applications Access an RDS DB Instance in a VPC?
- Do Applications Need to Support Reconnecting to the RDS DB Instance Automatically?
- Why Cannot I Ping My EIP After It Is Bound to a DB Instance?
- How Can I Obtain the IP Address of an Application?
- Can I Access an RDS DB Instance Over an Intranet Connection Across Regions?
- Is an SSL Connection to a DB Instance Interrupted After a Primary/Standby Switchover or Failover?
- Database Migration
- Database Permission
- Database Storage
- Client Installation
- Backup and Restoration
- Database Monitoring
- Capacity Expansion and Specification Change
- Database Parameter Modification
- Network Security
- Change History
- Troubleshooting
- Videos
Using RDS for MySQL Database Proxies for Read/Write Splitting
You can enable database proxy for your RDS for MySQL instance to automatically forward read and write requests though a proxy address. To reduce read pressure of the primary instance, write requests are forwarded to the primary instance and read requests to read replicas based on the routing policy of the database proxy.
This section describes how to use a database proxy to implement read/write splitting. The process is as follows:
- Step 1: Enable Database Proxy
- Step 2: Grant Access Permissions
- Step 3: Check Security Group Rules
- Step 4: Use a Proxy Address to Connect to an RDS for MySQL Instance
- Step 5: Verify Read/Write Splitting
Precautions
- Both the primary instance and read replicas must be available.
- You have learned the regions and versions that support database proxies. For details, see Constraints on Database Proxy.
- Only Pay-per-use can be selected for pay-per-use DB instances.
- Both pay-per-use and yearly/monthly proxy instances can be created for yearly/monthly DB instances. To create yearly/monthly proxy instances, you must contact customer service.
Step 1: Enable Database Proxy
- 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 target instance name to go to the Basic Information page.
- In the navigation pane on the left, choose Database Proxy.
Alternatively, in the Connection Information area on the Basic Information page, click Apply next to the Read/Write Splitting Address field.
Figure 1 Applying for a read/write splitting address - On the displayed page, click Create Database Proxy.
Figure 2 Creating database proxy
- On the displayed page, set the required parameters and click Next.
Figure 3 Setting Routing Policy to WeightedFigure 4 Setting Routing Policy to Load balancing
Table 1 Parameter description Parameter
Description
Billing Mode
- Only Pay-per-use can be selected for pay-per-use DB instances.
- Either Pay-per-use or Yearly/monthly can be selected for yearly/monthly DB instances. A pay-per-use proxy can be changed to a yearly/monthly proxy later. To create a yearly/monthly proxy, contact customer service to apply for required permissions.
Proxy Name
The proxy name must start with a letter and consist of 4 to 64 characters. Only letters (case-sensitive), digits, hyphens (-), and underscores (_) are allowed.
Role
- Read and write: Read and write requests are split.
- Read only: The proxy is not connected to your primary instance and cannot receive write requests.
Routing Policy
- Weighted: You can change the weights of your DB instance and read replicas after read/write splitting is enabled.
- Load balancing: If selected, to balance the load among read replicas, read requests are automatically distributed to multiple read replicas based on the number of active connections.
You can change the routing policy after the database proxy is created. For details, see Configuring the Delay Threshold and Routing Policy.
Read Requests Accepted by Primary DB Instance
This parameter is available only when Load balancing is selected.
- Yes: Read requests can be routed to both the primary instance and read replicas, which increases the load of the primary instance. Configure this parameter as required.
- No: Read requests are routed only to read replicas to offload read pressure from the primary instance.
New Instance Class
Select specifications for the proxy instance based on service requirements. You can change the specifications after the proxy instance is created. For details, see Changing the Instance Class of a DB Proxy Instance.
For details about performance metrics, see Table 2.
Proxy Nodes
Enter an integer from 2 to 8. You can change the nodes after the proxy instance is created. For details, see Changing the Number of Proxy Nodes.
You are advised to set proxy nodes to the quantity of read replicas, with one proxy node for one read replica.
Set Read Weight
This parameter is only available if Weighted is selected. Select the primary instance and read replicas to which you want to assign weights.
Rules for configuring read weights
- Read requests are allocated proportionate to the read weight you configure. For example, if you associate two read replicas with the proxy and set their read weights to 100 and 200, all read requests forwarded to the proxy are automatically routed to the read replicas in the ratio of 1:2 (the read weights for unselected instances is 0).
- A read replica can be associated with more than one proxy. To balance traffic among the read replicas of your primary instance, set read weights for them based on the existing proxies' weights and on the amount of traffic routed to the read replicas.
- You can change read weights of the primary instance and read replicas after read/write splitting is enabled. For details, see Configuring the Delay Threshold and Routing Policy.
Select DB Instances for Load Balancing
This parameter is available only when Load balancing is selected. Select the DB instances for load balancing.
After Load balancing is selected, the proxy forwards read requests to database nodes with fewer active connections.
You can change the DB instances for load balancing after read/write splitting is enabled. For details, see Configuring the Delay Threshold and Routing Policy.
- Confirm the database proxy configuration.
- To modify the configuration, click Previous.
- To submit the request, click Submit.
- View and manage the proxy on the Database Proxy page.
You can view the read/write splitting address on the Basic Information page. Read and write requests can be split through the read/write splitting address.
The read/write splitting address and the floating IP address of the DB instance are in the same VPC and subnet and are independent from each other.
Figure 5 Viewing the read/write splitting address
Step 2: Grant Access Permissions
Before using a database proxy to connect to an RDS for MySQL instance, ensure that the current database account has the permission to access the proxy address.
You can perform the following steps to check and grant an account the permission to access a proxy address.
- Connect to your RDS for MySQL instance.
- Check whether host of your account contains a database proxy address.
SELECT user,host FROM mysql.user;
- If the host does not contain the CIDR block where the database proxy is located, grant the access permission to the account.
For example, if you want to connect to an RDS for MySQL instance from the IP address range starting with 192.168.0 as the root user, you can set host of the account to 192.168.% on the user management page of Data Admin Service (DAS).
Step 3: Check Security Group Rules
Ensure that there is an inbound rule that allows access from the proxy address. The default port is 3306.
- On the Instances page, click the DB instance name.
- In the navigation pane, choose Connectivity & Security. In the Security Group Rules area, click the security group name to view the security group rules.
- On the Inbound tab, check whether access through port 3306 is allowed by default.
Figure 6 Allowing access through port 3306
If there is no such a rule, click Add Inbound Rule or Allow All IP.
Step 4: Use a Proxy Address to Connect to an RDS for MySQL Instance
- Check for the proxy address and port on the RDS for MySQL console.
- Log in to an ECS.
- Run the following command to connect to the RDS for MySQL instance through the proxy address:
mysql -h <hostIP> -P <port> -u <userName> -p <password>
Table 2 Parameter description Parameter
Description
<hostIP>
The proxy address obtained in 1.
<port>
The database port obtained in 1.
<userName>
The username of the database administrator account. The default username is root.
<password>
The password of the database administrator account.
NOTE:
When you use a MySQL 8.0 client to access a database proxy, the error message "auth user failed" may be displayed.
Add --default-auth=mysql_native_password when connecting to the database.
Step 5: Verify Read/Write Splitting
You can run the show last route command to check the routing result after you perform a read operation.
The following uses a read operation as an example to describe how to check the routing result of read requests.
- After connecting to your RDS for MySQL instance, perform a read operation.
Example: select 1;
- Run the following command to check the routing result of the read operation in 1:
show last route
Figure 7 Query resultNOTE:
Do not include show last route in service code or multi-statement requests.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.