tencent cloud

Hint Syntax Usage
Last updated: 2025-10-27 17:04:28
Hint Syntax Usage
Last updated: 2025-10-27 17:04:28
This document describes how to use the hint syntax on the database proxy.
The hint syntax can be used to forcibly execute SQL requests on the specified instance. A hint has the highest routing priority. For example, it is not subject to consistency and transaction constraints.You need to reasonably evaluate whether it is required in your business scenario before using it.
Note:
When using the MySQL command line tool to connect and use the HINT statement, you need to add the -c option in the command; otherwise, the hint will be filtered by the tool.
For example, the command should be mysql -h hostname -u username -p -c for connection through the private network.
The database proxy kernel version greater than or equal to version 1.1.3 supports PREPARE statement when the hint syntax is used through the database proxy.
Currently, four types of hints are supported:
Assign to the source instance for execution:
-- Hint statement
/* to master */
or
/*FORCE_MASTER*/
-- Example
-- Specify the primary instance to perform the query operation
SELECT /* to master */ * FROM users WHERE user_id = 1;

-- Specify the primary instance to perform the update operation
UPDATE /* FORCE_MASTER */ orders SET status = 'shipped' WHERE order_id = 1001;
Assign to a read-only instance for execution:
-- Hint statement
/* to slave */
or
/*FORCE_SLAVE*/
-- Example
-- Specify a read-only instance to perform the query operation
SELECT /* to slave */ * FROM products WHERE category = 'electronics';

-- Specify a read-only instance to perform the count operation
SELECT /* FORCE_SLAVE */ COUNT(*) FROM transactions WHERE status = 'completed';
Specify a read-only analysis engine for execution:
Note:
This execution method is only supported when the database proxy version is 1.4.4 or later. If multiple read-only analysis engines exist, load balancing will be performed based on weight rules.
-- Specify the read-only analysis engine to perform the query operation
SELECT /* to ap */ * FROM products WHERE category = 'electronics';
Specify an instance for execution:
-- Hint statement
/* to server server_name */
-- Example
-- Specify the instance test_ro_1 to perform the query operation
SELECT /* to server test_ro_1 */ * FROM inventory WHERE product_id = 2002;
Note:
server_name in the above statement indicates the instance ID. You can obtain the ID of the target instance on the instance details page, as shown in the figure below.

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback