os:centos 7.4
mysql: 5.7
proxysql: 1.4.10
ip 规划如下:
192.168.56.101 node1 (proxysql)
192.168.56.102 node2 (mysql master)
192.168.56.103 node3 (mysql slave)
192.168.56.104 node4 (mysql slave)
配置读写分离策略需要使用 mysql_query_rules 表。表中的 match_pattern 字段就是代表设置的规则,destination_hostgroup 字段代表默认指定的分组,apply 代表真正执行应用规则。
把所有以 select 开头的语句全部分配到编号为 2 的读组中。
select for update 会产生一个写锁,对数据查询的实效性要求高,把它分配到编号为 1 的写组中,其他所有操作都会默认路由到写组中。
读写分离规则 main.mysql_query_rules
Admin> use main;
Admin> select * from main.mysql_query_rules;
Empty set (0.00 sec)
Admin> insert into main.mysql_query_rules(active,match_pattern,destination_hostgroup, apply) VALUES(1,'^SELECT.*FOR UPDATE$',10,1);
Admin> insert into main.mysql_query_rules(active,match_pattern,destination_hostgroup, apply) VALUES(1,'^SELECT',20,1);
Admin> load mysql query rules to runtime;
Admin> save mysql query rules to disk;
更详细的操作,研究透彻后随时补充。
下面是一些proxysql常用的命令
# /etc/init.d/proxysql
Usage: ProxySQL {start|stop|status|reload|restart|initial}
生产环境切不可 initial。
加载或保存 users(mysql_users)
[1]: load mysql users to runtime / load mysql users from memory –将修改后的配置(在memory层)用到实际生产
[2]: save mysql users to memory / save mysql users from runtime –将生产配置拉一份到memory中
[3]: load mysql users to memory / load mysql users from disk –将磁盘中持久化的配置拉一份到memory中来
[4]: save mysql users to disk / save mysql users from memory –将memoery中的配置保存到磁盘中去
[5]: load mysql users from config –将配置文件中的配置加载到memeory中
加载或保存servers(mysql_servers):
[1]: load mysql servers to runtime –让修改的配置生效
[2]: save mysql servers to memory
[3]: load mysql servers to memory
[4]: save mysql servers to disk –将修改的配置持久化
[5]: load mysql servers from config
加载或保存 query rules(mysql_query_rules):
[1]: load mysql query rules to runtime
[2]: save mysql query rules to memory
[3]: load mysql query rules to memory
[4]: save mysql query rules to disk
[5]: load mysql query rules from config
加载或保存 mysql variables(global_variables):
(select * from global_variables where variable_name like ‘mysql-%’)
[1]: load mysql variables to runtime
[2]: save mysql variables to memory
[3]: load mysql variables to memory
[4]: save mysql variables to disk
[5]: load mysql variables from config
加载或保存 admin variables
(select * from global_variables where variable_name like ‘admin-%’):
[1]: load admin variables to runtime
[2]: save admin variables to memory
[3]: load admin variables to memory
[4]: save admin variables to disk
[5]: load admin variables from config
多读官方文档!!!
多读官方文档!!!
多读官方文档!!!
参考:
https://github.com/sysown/proxysql/wiki
https://github.com/sysown/proxysql/wiki/ProxySQL-Configuration
https://mp.weixin.qq.com/s?__biz=MjM5MDAxOTk2MQ==&mid=2650278687&idx=1&sn=a555463f6d0354f03f07e8807448e66f&chksm=be47930989301a1f74f221875cccd0ed6eb44edf8d0d15d1acd7942ac250cb7c8c36eabe1689&mpshare=1&scene=1&srcid=0622jjQdeJTqku1RPrBIzfro#rd