Mysqlnd replication and load balancing plugin (
mysqlnd_ms
)
2580
"slave": {
"slave_0": {
"host": "simulate_slave_failure",
"port": "0"
},
"slave_1": {
"host": "127.0.0.1",
"port": 3311
}
},
"filters": { "roundrobin": [] }
}
}
Example 20.251. Manual failover
<?php
$mysqli = new mysqli("myapp", "username", "password", "database");
if (!$mysqli)
/* Of course, your error handling is nicer... */
die(sprintf("[%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()));
$sql = "SELECT 1 FROM DUAL";
/* error handling as it should be done regardless of the plugin */
if (!($res = $link->query($sql))) {
/* plugin specific: check for connection error */
switch ($link->errno) {
case 2002:
case 2003:
case 2005:
printf("Connection error - trying next slave!\n");
/* load balancer will pick next slave */
$res = $link->query($sql);
break;
default:
/* no connection error, failover is unlikely to help */
die(sprintf("SQL error: [%d] %s", $link->errno, $link->error));
break;
}
}
if ($res) {
var_dump($res->fetch_assoc());
}
?>
20.7.6.4.10. Partitioning and Sharding
Copyright 1997-2012 the PHP Documentation Group. [2230]
Database clustering is done for various reasons. Clusters can improve availability, fault tolerance, and
increase performance by applying a divide and conquer approach as work is distributed over many
machines. Clustering is sometimes combined with partitioning and sharding to further break up a large
complex task into smaller, more manageable units.
The mysqlnd_ms plugin aims to support a wide variety of MySQL database clusters. Some flavors
of MySQL database clusters have built-in methods for partitioning and sharding, which could be
transparent to use. The plugin supports the two most common approaches: MySQL Replication table
filtering, and Sharding (application based partitioning).
MySQL Replication supports partitioning as filters that allow you to create slaves that replicate all or
specific databases of the master, or tables. It is then in the responsibility of the application to choose a
slave according to the filter rules. You can either use the mysqlnd_ms
node_groups
filter to manually
support this, or use the experimental table filter.
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 ...