Mysql read/write splitting using mysql-proxy

Source: Internet
Author: User

Environment: 192.168.100.210
192.168.100.104
192.168.100.208
192.168.100.106

Note: 210,104 is used as a mysql database.
208 as mysql-proxy.
106 as the testing machine.

Download related software:
Lua
Www.lua.org
Mysql-proxy
Http://mysql.cdpa.nsysu.edu.tw/Downloads/MySQL-Proxy/

1. Install lua on 208

# Tar zxvf lua-5.1.4.tar.gz-C/usr/local
# Cd/usr/local
# Mv lua-5.1.4 lua
# Cd lua
# Make // make: the system list is displayed.
Command to use
# Make linux // here is linux

# Make install

2. Install mysql-proxy

# Tar-zxvf mysql-proxy-0.6.0-linux-rhas4-x86.tar.gz-C/usr/local/
# Cd/usr/local/
# Mv mysql-proxy-0.6.0-linux-rhas4-x86 mysql-proxy
# Export PATH = $ PATH:/usr/local/mysql-proxy/sbin/
# Mysql-proxy -- proxy-read-only-backendaddresses = 192.168.100.210: 3306
-- Proxy-backend-addresses = 192.168.100.104: 3306
-- Proxy-lua-script =/home2/mysql-proxy-0.6.0-linux-rhas4-x86/share/mysql-proxy/rw-splitting.lua &


3. Set permissions on 210,104
Mysql> grant all privileges on backup. *
[Email = backup @ '%'] backup @ '%' [/email]
Identified by 'shenyun ';
// Here, a backup account and password shenxun are provided. The database for read and write operations is backup.

4. perform the test.

Connect mysql-proxy 106 with mysql 208:

/Usr/bin/mysql-u backup-pshenxun-P4040-h 192.168.100.208-D backup

Create a table

Create table haha (id int, name char (6 ));

Then we went to 210 and 104 to check the database. We can see that 210 is not the same
The database table to be written, while 104 has the data table just written.
Now let's modify the above command

Mysql-proxy -- proxy-backend-addresses = 192.168.100.210: 3306 -- proxy-backend-addresses = 192.168.100.104: 3306 -- proxy-lua-script =/home2/mysql-proxy-0.6.0-linux-rhas4-x86/share/mysql-proxy/rw-splitting.lua &

Then we create another table on 208.

Create table xixi (id int, name char (6 ));
At this time, I went to 210 and 104 to check the database and found that both databases had the data just written.
Database table.
This fully demonstrates that our database read/write splitting has been implemented.

Related Article

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.