Mysqlnd_ms is a MYSQLND plug-in, which realizes the function of saving and switching, load balancing, and read and write separation. To use the Mysqlnd_ms read-write detach feature, you must use –WITH-MYSQLND when you install PHP. MYSQLND implementation of the function is that you do not need to install MySQL on the PHP server, before php5.3 compile and install PHP need to –with-mysql=/path/to/mysql specify the MySQL installation path.
1. Install Mysqlnd_ms module
TAR-ZXVF mysqlnd_ms-1.5.2.tgz
CD mysqlnd_ms-1.5.2
/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-config
Make && make install
There are similar prompts to record that the following path requires a configuration php.ini
Installing Shared extensions:/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/
Installing header files:/usr/local/php/include/php/
2. Edit/usr/local/php/etc/php.ini
Extension =/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/mysqlnd_ms.so
Mysqlnd_ms.enable = On
Mysqlnd_ms.config_file =/usr/local/php/etc/mysqlnd_ms_plugin.ini
3. Create Mysqlnd_ms_plugin.ini configuration file
{
"MyApp": {
"Master": {
"Master_0": {
"Host": "192.168.6.135",
"Socket": "\/tmp\/mysql.sock"
}
"Slave": {
"Slave_0": {
"Host": "192.168.6.136",
"Port": "3306"
"Slave_1": {
"Host": "192.168.6.137",
"Port": "3306"
"Filters": {
"Random": {
"Sticky": "1"
}
}
}
}
This uses 1 main 2 MySQL servers from the
Filters is the policy to define access from the server, random is a random selection of a server, Strick parameter set to 1 refers to a single request to a server
4, testing
Use WordPress for testing, edit profile wp-config.php
/** MySQL Host * *
Define (' Db_host ', ' MyApp '); defined in #这的myapp是在mysqlnd_ms_plugin. ini