![background image](http://html1.mh-extra.com/html/oracle/5-0/5-0_reference-manual_16461962656.webp)
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.
Содержание 5.0
Страница 1: ...MySQL 5 0 Reference Manual ...
Страница 18: ...xviii ...
Страница 60: ...40 ...
Страница 396: ...376 ...
Страница 578: ...558 ...
Страница 636: ...616 ...
Страница 844: ...824 ...
Страница 1234: ...1214 ...
Страница 1426: ...MySQL Proxy Scripting 1406 The following diagram shows an overview of the classes exposed by MySQL Proxy ...
Страница 1427: ...MySQL Proxy Scripting 1407 ...
Страница 1734: ...1714 ...
Страница 1752: ...1732 ...
Страница 1783: ...Configuring Connector ODBC 1763 ...
Страница 1793: ...Connector ODBC Examples 1773 ...
Страница 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Страница 1842: ...Connector Net Installation 1822 5 Once the installation has been completed click Finish to exit the installer ...
Страница 1864: ...Connector Net Visual Studio Integration 1844 Figure 20 24 Debug Stepping Figure 20 25 Function Stepping 1 of 2 ...
Страница 2850: ...2830 ...
Страница 2854: ...2834 ...
Страница 2928: ...2908 ...
Страница 3000: ...2980 ...
Страница 3122: ...3102 ...
Страница 3126: ...3106 ...
Страница 3174: ...3154 ...
Страница 3232: ...3212 ...