Oracle 5.0 Reference Manual page 2656

Table of Contents

Advertisement

Mysqlnd replication and load balancing plugin (mysqlnd_ms)
The constants below are defined by this extension, and will only be available when the extension has
either been compiled into PHP or dynamically loaded at runtime.
SQL hint related
Example 20.296. Example demonstrating the usage of mysqlnd_ms constants
The mysqlnd replication and load balancing plugin (mysqlnd_ms) performs read/write splitting. This
directs write queries to a MySQL master server, and read-only queries to the MySQL slave servers.
The plugin has a built-in read/write split logic. All queries which start with
only queries, which are then sent to a MySQL slave server that is listed in the plugin configuration
file. All other queries are directed to the MySQL master server that is also specified in the plugin
configuration file.
User supplied SQL hints can be used to overrule automatic read/write splitting, to gain full control on
the process. SQL hints are standards compliant SQL comments. The plugin will scan the beginning of
a query string for an SQL comment for certain commands, which then control query redirection. Other
systems involved in the query processing are unaffected by the SQL hints because other systems will
ignore the SQL comments.
The plugin supports three SQL hints to direct queries to either the MySQL slave servers, the MySQL
master server, or the last used MySQL server. SQL hints must be placed at the beginning of a query to
be recognized by the plugin.
For better portability, it is recommended to use the string constants
MYSQLND_MS_SLAVE_SWITCH
<?php
/* Use constants for maximum portability */
$master_query = "/*" . MYSQLND_MS_MASTER_SWITCH . "*/SELECT id FROM test";
/* Valid but less portable: using literal instead of constant */
$slave_query = "/*ms=slave*/SHOW TABLES";
printf("master_query = '%s'\n", $master_query);
printf("slave_query = '%s'\n", $slave_query);
?>
The above examples will output:
master_query = /*ms=master*/SELECT id FROM test
slave_query = /*ms=slave*/SHOW TABLES
MYSQLND_MS_MASTER_SWITCH
(string)
MYSQLND_MS_SLAVE_SWITCH
(string)
MYSQLND_MS_LAST_USED_SWITCH
(string)
mysqlnd_ms_query_is_select
MYSQLND_MS_QUERY_USE_MASTER
(integer)
and
MYSQLND_MS_LAST_USED_SWITCH
SQL hint used to send a query to the MySQL replication master
server.
SQL hint used to send a query to one of the MySQL replication
slave servers.
SQL hint used to send a query to the last used MySQL server. The
last used MySQL server can either be a master or a slave server in
a MySQL replication setup.
related
If
mysqlnd_ms_is_select
MYSQLND_MS_QUERY_USE_MASTER
in read/write split mechanism recommends sending the query to a
MySQL replication master server.
2636
are considered read-
SELECT
MYSQLND_MS_MASTER_SWITCH
instead of their literal values.
returns
for a given query, the built-
,

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents