Mysqlnd replication and load balancing plugin (
mysqlnd_ms
)
2636
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
SELECT
are considered read-
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_MASTER_SWITCH
,
MYSQLND_MS_SLAVE_SWITCH
and
MYSQLND_MS_LAST_USED_SWITCH
instead of their literal values.
<?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)
SQL hint used to send a query to the MySQL replication master
server.
MYSQLND_MS_SLAVE_SWITCH
(string)
SQL hint used to send a query to one of the MySQL replication
slave servers.
MYSQLND_MS_LAST_USED_SWITCH
(string)
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.
mysqlnd_ms_query_is_select
related
MYSQLND_MS_QUERY_USE_MASTER
(integer)
If
mysqlnd_ms_is_select
returns
MYSQLND_MS_QUERY_USE_MASTER
for a given query, the built-
in read/write split mechanism recommends sending the query to a
MySQL replication master server.
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...