Help Center/ TaurusDB/ User Guide/ Database Proxy (Read/Write Splitting)/ Using Hints for Read/Write Splitting
Updated on 2026-09-16 GMT+08:00

Using Hints for Read/Write Splitting

In addition to configuring weights of nodes for read/write splitting, you can use hints in SQL statements to route read and write requests to a primary node or read replica.

Precautions

  • Hints are only used as routing suggestions. In non-read-only SQL and non-transaction scenarios, SQL statements cannot be routed to read replicas.
  • If you want to connect to a DB instance through the MySQL CLI and use hints in SQL statements, you must add the -c option to the statements. Otherwise, the hints will be filtered out by the MySQL CLI.

Usage

You can add the following hints at the beginning of an SQL statement as needed.

/*FORCE_MASTER*/: The SQL statement is executed on the primary node.

/*FORCE_SLAVE*/: The SQL statement is executed on read replicas.

For example, if you run select * from table1, the SQL statement will be executed on a read replica by default. If you change it to /*FORCE_MASTER*/ select * from table1, the SQL statement will be executed on the primary node.

/*FORCE_MASTER*/ only works for read/write addresses. If a read-only address is used, requests will not be routed to the primary node even if /*FORCE_MASTER*/ is specified.