Read-write splitting

The plugin runs read-only statements on the configured MySQL slaves and all other queries on the MySQL master. Statements are considered read-only if they either start with SELECT, the SQL hint /*ms=slave*/ or a slave had been chosen for running the previous query and the query starts with the SQL hint /*ms=last_used*/. In all other cases the query will be send to the MySQL replication master server.

SQL hints are a special kind of standard compliant SQL comments. The plugin does check every statement for certain SQL hints. The SQL hints are described together with the constants exported by the extension. Other systems involved in the statement processing, such as the MySQL server, SQL firewalls or SQL proxies are unaffected by the SQL hints because those systems are supposed to ignore SQL comments.

The built-in read-write splitter can be replaced by a user-defined one, see also mysqlnd_ms_set_user_pick_server().

A user-defined read-write splitter can ask the built-in logic to make a proposal where to sent a statement by invoking mysqlnd_ms_is_select().


The built-in read-write splitter is not aware of multi-statements. Multi-statements are seen as one statement. The splitter will check the beginning of the statement to decide where to run the statement. If, for example, a multi-statement begins with SELECT 1 FROM DUAL; INSERT INTO test(id) VALUES (1); ... the plugin will run it on a slave although the statement is not read-only.

add a note add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top