proxySQL做mysql读写分离

六月ゝ 毕业季﹏ 提交于 2020-02-26 15:42:51

proxySQL做mysql读写分离:

参考网址:
https://cloud.tencent.com/developer/article/1429052

下载网址:
http://repo.proxysql.com/ProxySQL/proxysql-2.0.x/centos/6/proxysql-2.0.8-1-centos67.x86_64.rpm

官方网址:
https://www.proxysql.com

yum install perl-DBD-MySQL

rpm -i proxysql-2.0.8-1-centos67.x86_64.rpm

配置文件路径:/etc/proxysql.cnf
默认数据路径:/var/lib/proxysql/

vi /etc/proxysql.cnf

mysql_ifaces="127.0.0.1:6032;/tmp/proxysql_admin.sock"

interfaces="10.0.1.2:6033;/tmp/proxysql.sock"

monitor_username="ming"
monitor_password="xxxxxx"

{ address="10.0.1.3" , port=3306 , hostgroup=10 },
{ address="10.0.1.4" , port=3306 , hostgroup=20 },
{ address="10.0.1.5" , port=3306 , hostgroup=20 },

mysql_users:
(
{
username = "ming" # no default , required
password = "xxxxxxx" # default: ''
default_hostgroup = 10 # default: 0
active = 1 # default: 1
},

mysql_query_rules:
(
{
rule_id=1
active=1
match_pattern="^SELECT .* FOR UPDATE$"
destination_hostgroup=10
apply=1
},
{
rule_id=2
active=1
match_pattern="^SELECT"
destination_hostgroup=20
apply=1
}
)

mysql_replication_hostgroups=
(
{
writer_hostgroup=10
reader_hostgroup=20
comment="test repl 1"
},

:wq

service proxysql start

netstat -ntpl | grep 60 (6032为管理端口,6033为数据端口)

mysql -u admin -p'admin' -P6032 -h 127.0.0.1

show databases;

select from mysql_server_connect_log; (查看后端mysql服务器连接状态)
select
from mysql_servers; (查看后端mysql服务器)

验证:

只读:

mysql -h 10.0.1.2 -u ming -p'xxxxxx' -P6033 -e "select @@hostname;"

写入:

mysql -h 10.0.1.2 -u ming -p'xxxxx' -P6033 -e "begin;insert ming.test value('aa',10,30);select @@hostname;commit;"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!