标签:oca 操作 varchar arch als zha creat add level
1、安装mysql-proxy
实现读写分离是有lua脚本实现的,现在mysql-proxy里面已经集成,无需再安装
下载:http://dev.mysql.com/downloads/mysql-proxy/
tar
zxvf mysql-proxy-0.8.3-linux-glibc2.3-x86-64bit.
tar
.gz
mv
mysql-proxy-0.8.3-linux-glibc2.3-x86-64bit
/usr/local/mysql-proxy
cd
/usr/local/mysql-proxy
mkdir
lua
#创建脚本存放目录
mkdir
logs
#创建日志目录
cp
share
/doc/mysql-proxy/rw-splitting
.lua .
/lua
#复制读写分离配置文件
cp
share
/doc/mysql-proxy/admin-sql
.lua .
/lua
#复制管理脚本
vi
/etc/mysql-proxy
.cnf
#创建配置文件
[mysql-proxy]
user=root
#运行mysql-proxy用户
admin-username=proxy
#主从mysql共有的用户
admin-password=123.com
#用户的密码
proxy-address=192.168.0.204:4040
# 如果不写端口号,默认端口号3306,与Mysql的端口号冲突,所以会报错。*************************!!!!
proxy-
read
-only-backend-addresses=192.168.0.203
#指定后端从slave读取数据
proxy-backend-addresses=192.168.0.202
#指定后端主master写入数据
proxy-lua-script=
/usr/local/mysql-proxy/lua/rw-splitting
.lua
#指定读写分离配置文件位置
admin-lua-script=
/usr/local/mysql-proxy/lua/admin-sql
.lua
#指定管理脚本
log-
file
=
/usr/local/mysql-proxy/logs/mysql-proxy
.log
#日志位置
log-level=info
#定义log日志级别,由高到低分别有(error|warning|info|message|debug)
daemon=
true
#以守护进程方式运行
keepalive=
true
#mysql-proxy崩溃时,尝试重启
保存退出!
chmod 660 /etc/mysql-proxy.cnf
vi
/usr/local/mysql-proxy/lua/rw-splitting
.lua
if
not proxy.global.config.rwsplit
then
proxy.global.config.rwsplit = {
min_idle_connections = 1,
#默认超过4个连接数时,才开始读写分离,改为1
max_idle_connections = 1,
#默认8,改为1
is_debug =
false
}
end
/usr/local/mysql-proxy/bin/mysql-proxy
--defaults-
file
=
/etc/mysql-proxy
.cnf
netstat
-tupln |
grep
4040
#已经启动
tcp 0 0 192.168.0.204:4040 0.0.0.0:* LISTEN 1264
/mysql-proxy
关闭mysql-proxy使用:killall -9 mysql-proxy
mysql> grant all on *.* to
‘proxy‘
@
‘192.168.0.204‘
identified by
‘123.com‘
;
mysql> create table user (number INT(10),name VARCHAR(255));
mysql> insert into user
values(01,
‘zhangsan‘
);
mysql> insert into user values(02,
‘lisi‘
);
参考文献:http://lizhenliang.blog.51cto.com/7876557/1305083
参考文献2:http://www.cnblogs.com/luckcs/articles/2543607.html
标签:oca 操作 varchar arch als zha creat add level
原文地址:http://www.cnblogs.com/meiping/p/6912749.html