A tutorial on the use of Mysqlnd Mysqlnd_ms plug-ins to achieve MySQL read-write separation

Source: Internet
Author: User
Tags configuration php install php ini mysql host php server zts

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.