Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Best Practices for Database Proxy

Updated on 2024-04-11 GMT+08:00

User Authentication and Connection

  1. A user must have the remote login permission before using a database proxy to log in to databases.

    To check whether the host of the account contains the CIDR block for read/write splitting, run the following SQL statement:

    SELECT user,host FROM mysql.user;

    If the host does not contain the CIDR block, you need to grant remote access permissions. For example, you could run the following command to grant user root the permissions to connect to the MySQL server from 192.168.0.X:

    GRANT
    ALL PRIVILEGES ON *.* TO 'root'@'192.168.0.%' IDENTIFIED BY password  WITH GRANT 
    OPTION;
    flush privileges;
    To query the CIDR block for read/write splitting, perform the following steps:
    1. On the Basic Information page of the primary instance, click the subnet name in the Connection Information area to go to the subnet console.
    2. Find IPv4 CIDR Block on the Summary page.
  2. When modifying a security group, ensure that the inbound and outbound rules allow access to the read/write splitting address. The default port for read/write splitting is 3306.
    1. Log in to the management console.
    2. Click in the upper left corner and select a region and a project.
    3. Click Service List. Under Database, click Relational Database Service. The RDS console is displayed.
    4. On the Instance Management page, click in front of the DB instance and click a read replica to go to the Basic Information page.
    5. In the Connection Information area, click the security group.
    6. On the Inbound Rules tab, check whether access through port 3306 is allowed by default. If this rule does not exist, click Fast-Add Rule. In the displayed dialog box, select MySQL (3306) and click OK.
  3. Database proxy does not support the identity authentication plugin caching_sha2_password of RDS for MySQL 8.0. If the error message "auth user failed" is displayed while you are attempting to access a database proxy using an RDS for MySQL 8.0 client, run the following SQL statement to check whether the identity authentication plugin is mysql_native_password:
    select plugin from mysql.user where user="Username";

    • If yes, add --default-auth=mysql_native_password or use an RDS for MySQL 5.* client to connect to the database proxy.

    • If no, run the following SQL statements to change the identity authentication plugin to mysql_native_password:
      ALTER USER 'Username'@'%' IDENTIFIED WITH 'mysql_native_password' BY 'Password';
      FLUSH PRIVILEGES;

Connection Pool Configuration

To ensure that your application obtains an available connection from a connection pool, you need to configure how the connection pool will check connection availability. For example, set testOnBorrow to true for a JDBC or Druid connection pool or set connectionTestQuery to SELECT 1 for a HikariCP connection pool.

Read Requests Routed to the Primary DB Instance

  1. If a query statement is placed in a transaction, all transaction requests will be routed to the primary DB instance. If set autocommit=0 is configured before a query statement, the query statement will be treated as a transaction and routed to the primary DB instance.
  2. If no read replica exists, all read replicas are abnormal, or the read weights allocated to the read replicas are 0, queries will be routed to the primary DB instance. You can set read weights allocated to read replicas and the primary DB instance after read/write splitting is enabled. For details, see Configuring Delay Threshold and Distributing Read Weight.
  3. If multiple statements (for example, insert xxx;select xxx) are executed, all subsequent requests will be routed to the primary DB instance. To restore read/write splitting, disconnect the connection from your applications and then reconnect.
  4. Read operations with locks (for example, SELECT for UPDATE) will be routed to the primary DB instance.
  5. When the /*FORCE_MASTER*/ hint is used, requests will be routed to the primary DB instance.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback