通过mysql-proxy完成mysql读写分离
时间:2024-01-24 03:13:09
环境: 192.168.100.210
192.168.100.104
192.168.100.208
192.168.100.106
说明: 210,104作为mysql数据库.
208作为mysql-proxy.
106作为测试机器.
相关软件下载:
lua
www.lua.org
mysql-proxy
http://mysql.cdpa.nsysu.edu.tw/Downloads/MySQL-Proxy/
1. 在208上安装lua
#tar zxvf lua-5.1.4.tar.gz -C /usr/local
# cd /usr/local
#mv lua-5.1.4 lua
#cd lua
#make //make之后可以看到系统列表,下面的
命令要用到
#make linux //我这里是linux
#make install
2.安装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.在210,104上设置权限
mysql> grant all privileges on backup.* to
[email=backup@'%']backup@'%'[/email]
identified by 'shenxun';
//这里给个账号backup,密码shenxun,读写操作的数据库是backup.
4.进行测试.
用106连接208的mysql-proxy:
/usr/bin/mysql -u backup -pshenxun –P4040 –h 192.168.100.208 –D backup
创建一个表
Create table haha(id int,name char(6));
然后我们到210和104上去看下数据库的情况,看到210是没有刚才
写入的数据库表,而104是有刚才写入的数据表的.
现在我们把上面的命令修改下
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 &
然后我们在208上再重新建个表
Create table xixi(id int,name char(6));
这个时候再到210和104上去看下数据库的情况,发现2个数据库都有刚才写入的数据
库表.
可以充分说明我们的数据库读写分离已经实现了
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Pytorch Tensor的索引与切片例子
python+mysql实现简单的web程序
关于vs2019安装不了扩展问题的解决方法
![](https://img.aspxhome.com/file/2023/9/132399_0s.png)
对pandas的行列名更改与数据选择详解
![](https://img.aspxhome.com/file/2023/0/90510_0s.jpg)
sqlserver数据库主键的生成方式小结(sqlserver,mysql)
Python 图像处理之颜色迁移(reinhard VS welsh)
![](https://img.aspxhome.com/file/2023/1/117371_0s.jpg)
javascript数组的使用
通过C++学习Python
原创一个js对联广告类(兼容FireFox)
Python中拆分具有多个分隔符的字符串方法实例
![](https://img.aspxhome.com/file/2023/0/81720_0s.png)
python3检查字典传入函数键是否齐全的实例
SQL Server 2008打开输入sa密码提示无法登陆数据库的解决方法
![](https://img.aspxhome.com/file/2023/0/92730_0s.jpg)
对python当中不在本路径的py文件的引用详解
Perl与JS的对比分析(数组、哈希)
![](https://img.aspxhome.com/file/2023/5/65835_0s.png)
JS+ASP实现无刷新新闻列表之分页
使用Filter过滤python中的日志输出的实现方法
不同分辨率下的自适用宽度
![](https://img.aspxhome.com/file/UploadPic/200811/24/2008112413340367s.jpg)
SQL 中having 和where的区别分析
创建Django项目图文实例详解
![](https://img.aspxhome.com/file/2023/7/110227_0s.png)
详解Tensorflow不同版本要求与CUDA及CUDNN版本对应关系
![](https://img.aspxhome.com/file/2023/5/103495_0s.png)