Mysqlnd replication and load balancing plugin (
mysqlnd_ms
)
2629
Upon connect the
mysqlnd
plugin compares the hostname with all section names from the plugin
configuration file. If hostname and section name match, the plugin will load the sections settings.
Example 20.292. Using section names example
[myapp]
master[] = localhost
slave[] = 192.168.2.27
slave[] = 192.168.2.28:3306
[localhost]
master[] = localhost:/tmp/mysql/mysql.sock
slave[] = 192.168.3.24:3305
slave[] = 192.168.3.65:3309
<?php
/* All of the following connections will be load balanced */
$mysqli = new mysqli("myapp", "username", "password", "database");
$pdo = new PDO('mysql:host=myapp;dbname=database', 'username', 'password');
$mysql = mysql_connect("myapp", "username", "password");
$mysqli = new mysqli("localhost", "username", "password", "database");
?>
Section names are strings. It is valid to use a section name such as
192.168.2.1
,
127.0.0.1
or
localhost
. If, for example, an application connects to
localhost
and a plugin configuration section
[localhost]
exists, the semantics of the connect operation are changed. The application will no
longer only use the MySQL server running on the host
localhost
but the plugin will start to load
balance MySQL queries following the rules from the
[localhost]
configuration section. This way you
can load balance queries from an application without changing the applications source code.
The
master[]
,
slave[]
and
pick[]
configuration directives use a list-like syntax. Configuration
directives supporting list-like syntax may appear multiple times in a configuration section. The plugin
maintains the order in which entries appear when interpreting them. For example, the below example
shows two
slave[]
configuration directives in the configuration section
[myapp]
. If doing round-
robin load balancing for read-only queries, the plugin will send the first read-only query to the MySQL
server
mysql_slave_1
because it is the first in the list. The second read-only query will be send
to the MySQL server
mysql_slave_2
because it is the second in the list. Configuration directives
supporting list-like syntax result are ordered from top to bottom in accordance to their appearance
within a configuration section.
Example 20.293. List-like syntax
[myapp]
master[] = mysql_master_server
slave[] = mysql_slave_1
slave[] = mysql_slave_2
Here is a short explanation of the configuration directives that can be used.
master[]
string
URI of a MySQL replication master server. The URI follows the
syntax
hostname[:port|unix_domain_socket]
.
The plugin supports using only one master server.
Setting a master server is mandatory. The plugin will report
a warning upon connect if the user has failed to provide a
master server for a configuration section. The warning may read
(mysqlnd_ms) Cannot find master section in config
.
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 ...