MySQL read-write separation

Source: Internet
Author: User
Tags lua

Mysql-proxy: For short, MySQL read-write separation; The main purpose is to improve the speed of Web site access.


First build MySQL master and slave, reference: http://syklinux.blog.51cto.com/9631548/1737317


Download Mysql-proxy:

Cd/usr/local/src

wget http://cdn.mysql.com/archives/mysql-proxy/mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit.tar.gz

Tar zxvf mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit.tar.gz

Cp-r Mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit/usr/local/mysql-proxy

Authorized:

chmod 755/usr/local/mysql-proxy

Chown-r Mysql:mysql/usr/local/mysql-proxy

Set Environment variables:

Vim/etc/profile

Add to:

Lua_path= "/usr/local/mysql-proxy/share/doc/mysql-proxy/?" Lua

Export Lua_path

Export path= $PATH:/usr/local/mysql-proxy/bin

After exiting:

Source/etc/profile

To create a MySQL user:

MySQL master and slave need to create the same user and password:
Grant all on * * to ' test ' @ ' percent ' identified by ' 123456 ';

To create a new mysql-proxy configuration file:

Vim/etc/mysql-proxy.cnf

Add to:

[Mysql-proxy]

Admin-username = Test

Admin-password = 123456

Daemon = True

KeepAlive = True

Proxy-backend-addresses = 192.168.1.2:3306

Proxy-read-only-backend-addresses = 192.168.1.2:3307

Proxy-lua-script =/usr/local/proxy-mysql/share/doc/mysql-proxy/rw-splitting.lua

Admin-lua-script =/usr/local/proxy-mysql/share/doc/mysql-proxy/admin-sql.lua

Log-file =/usr/local/proxy-mysql/cn.log

Log-level = Debug

Main parameters:

proxy-backend-addresses MySQL Main library (write) address

Proxy-read-only-backend-addresses MySQL from library (read) address

Proxy-lua-script read-Write separation script

Admin-lua-script Admin Script

Admin-username database user name (the same user must be established on both master and slave)

Admin-password Database Password

Daemon Daemon Process Run

KeepAlive remain connected (START process will have 2, a process is used to monitor > second, if the second process died automatic reconstruction, this parameter is not available in the old version)

To create a mysql-proxy startup script:

Vim/etc/init.d/mysql-proxy

#!/bin/bash

Mode=$1

If [-Z "$mode"]; Then

Mode= "Start"

Fi

Case $mode in

Start

Mysql-proxy--defaults-file=/etc/mysql-proxy.cnf>/usr/local/proxy-mysql/cn.log &

;;

Stop

Killall-9 Mysql-proxy

;;

Restart

if $ stop; Then

$ start

Else

echo "Restart failed!"

Exit 1

Fi

;;

Esac

Exit 0

Authorized:

chmod 755/etc/init.d/mysql-proxy

Chkconfig--add Mysql-proxy

Start Mysql-proxy:

Service Mysql-proxy Start

This article is from the "Linux" blog, so be sure to keep this source http://syklinux.blog.51cto.com/9631548/1743794

MySQL read-write separation

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.