ProxySQL–基础–2.4–部署–管理MSYQL节点
1、介绍
让ProxySQL管理后端的mysql节点
1.1、任务描述
把后端的MySQL节点
,添加到main库
的对应表中,ProxySQL就能找到MySQL节点
1.2、步骤
- 将 后端MySQL节点 的主从复制结构配置好。
- ProxySQL 添加MySQL节点**(必须的步骤)**
- 相关的表:mysql_servers。
- 监控后端MySQL节点**(必须的步骤)**
- 相关的表:全局变量表
global_vairbles
- 相关的变量:mysql-monitor_ 开头的变量。
- 相关的表:全局变量表
- 对ProxySQL中的节点分组(非必须的步骤)
- 相关的表:
mysql_replication_hostgroups
。
- 相关的表:
- 添加 普通用户**(必须的步骤)**
- 用于发送SQL语句。
- 相关的表:
mysql_users
。
1.3、注意点
1.3.1、注意1
ProxySQL简单路由是通过监控后端节点的read_only值来自动调整节点所属组的
- read_only=1的节点会移动到读组
- read_only=0的节点会移动到写组。
所以,在配置读、写组之前,需要先监控后端mysql节点。
ProxySQL支持手动管理后端节点,这种模式不会根据read_only的值自动调整,在后面的文章中会介绍这种模式。
1.3.2、注意2
- 对于传统的主从复制:默认的read_only=0,所以在第1步中,各slave节点的配置文件中需要加上read_only=1。
- 对于组复制、Galera:因为会自动强制设置非写节点的read_only=1,所以无需额外配置该属性。
1.3.3、注意3
- ProxySQL支持 传统主从复制结构(即异步、半同步、gtid复制)的后端mysql
- 读、写组相关的表是:
mysql_replication_hostgroups
。
- 读、写组相关的表是:
- ProxySQL支持 MySQL组复制结构的后端mysql
- 相关的表是
mysql_group_replication_hostgroups
- 相关的表是
- ProxySQL支持 Galera(如percona XtraDB cluster)结构的后端mysql,不过ProxySQL是通过scheduler调度
proxysql_galera_checker.sh
脚本来支持Galera的- 相关的表是
mysql_galera_hostgroups
- 相关的表是
1.4、准备环境
mysql1主2从
ProxySQL--基础--2.3--部署--准备测试环境--mysql1主2从
1.4.1、机器信息
名称 | Ip | Port | server_id |
---|---|---|---|
M1 | 192.168.187.88 | 3307 | 110 |
M1S1 | 192.168.187.88 | 3308 | 120 |
M1S2 | 192.168.187.88 | 3309 | 130 |
Proxysql | 192.168.187.88 | 6032,6033 | null |
1.4.2、架构图
2、ProxySQL 添加MySQL节点
ProxySQL机器操作
2.1、使用mysql客户端连接到ProxySQL的管理接口
默认管理员用户和密码都是admin
# 连接到ProxySQL的管理接口
mysql -uadmin -padmin -P6032 -h127.0.0.1;
2.2、向ProxySQL中添加MySQL节点
要加入3个后端MySQL节点,只需向mysql_servers表插入3行对应的记录即可。以下是使用了一大堆默认值的insert语句
insert into mysql_servers(hostgroup_id,hostname,port)values(10,'192.168.187.88',3307);
insert into mysql_servers(hostgroup_id,hostname,port)values(10,'192.168.187.88',3308);
insert into mysql_servers(hostgroup_id,hostname,port)values(10,'192.168.187.88',3309);
# 将配置加载到RUNTIME,使其可以立马生效,并保存到disk。
load mysql servers to runtime;
save mysql servers to disk;
注:上面语句中没有先切换到main库也执行成功了,因为ProxySQL内部使用的SQLite3数据库引擎,和MySQL的解析方式是不一样的。即使执行了USE main语句也是无任何效果的,但不会报错。
2.2.1、查看这3个节点是否插入成功,以及它们的状态
mysql> select * from mysql_servers\G
*************************** 1. row ***************************
hostgroup_id: 10
hostname: 192.168.187.88
port: 3307
status: ONLINE
weight: 1
compression: 0
max_connections: 1000
max_replication_lag: 0
use_ssl: 0
max_latency_ms: 0
comment:
*************************** 2. row ***************************
hostgroup_id: 10
hostname: 192.168.187.88
port: 3308
status: ONLINE
weight: 1
compression: 0
max_connections: 1000
max_replication_lag: 0
use_ssl: 0
max_latency_ms: 0
comment:
*************************** 3. row ***************************
hostgroup_id: 10
hostname: 192.168.187.88
port: 3309
status: ONLINE
weight: 1
compression: 0
max_connections: 1000
max_replication_lag: 0
use_ssl: 0
max_latency_ms: 0
comment:
3 rows in set (0.00 sec)
2.2.2、注意
同一个节点是可以同时存在于多个组中的。最典型的情形是master既充当写节点,也充当读节点,这时它就同时存在于写组和读组。
2.3、mysql_servers表说明
字段 | 数据类型 | 允许null | 默认值 |
---|---|---|---|
hostgroup_id (pk) | int | not null | 0 |
hostname (pk) | varchar | not null | 无 |
port (pk) | int | not null | 3306 |
status | varchar | not null | online |
weight | int | not null | 1 |
compression | int | not null | 0 |
max_connections | int | not null | 1000 |
max_replication_lag | int | not null | 0 |
use_ssl | int | not null | 0 |
max_latency_ms | int | not null | 0 |
comment | varchar | not null | ‘’ |
添加一个节点时,除了刚刚3个字段,其它使用的全是字段的默认值。
MYSQL--架构--ProxySQL--03--库和表
4、mysql_servers表
3、监控后端MySQL节点
监控用户 用于监控后端节点。对于后端是主从复制的环境来说,这是必须的,因为ProxySQL通过Monitor模块监控后端MySQL Server的read_only值来自动调整节点所属的组。所以,在配置读、写组之前,必须先配置好监控。
3.1、Monitor监控4种指标
- connect
- ping
- read_only
- replication lag
3.1.1、通过Monitor库,可以查看对应指标的表
mysql -uadmin -padmin -P6032 -h127.0.0.1
# 查看下Monitor库中的表:
mysql> show tables from monitor;
+------------------------------------+
| tables |
+------------------------------------+
| mysql_server_connect_log |
| mysql_server_group_replication_log |
| mysql_server_ping_log |
| mysql_server_read_only_log |
| mysql_server_replication_lag_log |
+------------------------------------+
5 rows in set (0.00 sec)
3.1.2、connect监控
- ProxySQL连接到各后端是否成功
- 成功/失败的连接将记录到表
mysql_server_connect_log
中。
3.1.3、ping监控
-
这是一种心跳检测。
-
Monitor模块向所有后端MySQL节点发起ping检查,ping成功/失败的情况将记录到表
mysql_server_ping_log
中。当ping某后端的失败次数达到了mysql-monitor_ping_max_failures
时表示失去心跳,将发送一个信号给MySQL的主机组管理器来杀掉和该后端节点的所有连接。 -
请和connect监控区分开,connect监控是通过建立连接来检测和后端节点连接的连通性。ping监控是心跳检测,ProxySQL通过MySQL的一个ping API发送给后端MySQL服务上,然后等待ping回复,虽然是ping检测,但也是需要建立连接的。
所以,有两个确定连接不可用公式:
mysql-monitor_ping_max_failures * mysql-monitor_connect_timeout
mysql-monitor_ping_max_failures * mysql-monitor_ping_timeout
3.1.4、read_only监控
检查mysql_replication_hostgroups表中所有节点的read_only值,并记录到mysql_server_read_only_log
。
- 如果read_only=1,表示只读,是一个slave,这样的节点将会自动移入reader_hostgroup中。
- 如果read_only=0,表示可写,可能是master,这样的节点将会自动移入writer_hostgroup中。
3.1.5、replication lag监控
-
对
mysql_servers
表中所有配置了max_replication_lag
的后端slave节点都检查复制延迟,通过show slave status
返回结果中的Seconds_Behind_Master
字段,判断slave和master之间的延迟程度,并记录到mysql_server_replication_lag_log
表中。 -
如果
Seconds_Behind_Master > max_replication_lag
,表示该slave延迟很严重,ProxySQL会自动避开这种slave节点,直到Seconds_Behind_Master < max_replication_lag
。 -
Monitor监控上述指标时,会使用MySQL节点上的用户连接到后端节点,所以,需要先在后端节点上创建负责监控的用户。监控connect、ping和read_only这3项指标时,该用户只需具有USAGE权限,如果要监控replication lag指标,则需要replication client权限。
3.2、配置connect和ping监控
- 首先在后端mysql的 master节点上创建一个用于监控的用户名,这个用户名只需具有USAGE权限即可。
- 只需在master上创建即可,因为会复制到slave上
- 如果还需要监控复制结构中slave是否严重延迟于master(先混个眼熟:这个俗语叫做
拖后腿
,术语叫做replication lag
),则还需具备replication client权限。这里直接赋予这个权限
具体细节看
ProxySQL--基础--3.2--用户--管理用户
# 4、添加 监控用户
3.2.1、在mysql的master 节点上 创建一个监控用户
# 进入容器
docker exec -it M1 bash ;
# 进入mysql
mysql -uroot -proot ;
# 创建用户和权限
create user monitor@'192.168.187.%' identified by '123456';
grant replication client on *.* to monitor@'192.168.187.%';
3.2.2、配置监控用户
# 连接到ProxySQL的管理接口
mysql -uadmin -padmin -P6032 -h127.0.0.1;
set mysql-monitor_username='monitor';
set mysql-monitor_password='123456';
# 配置需要加载到RUNTIME,并保存到disk。
load mysql variables to runtime;
save mysql variables to disk;
# 可以通过下面语句查询
select * from global_variables WHERE variable_name='mysql-monitor_username'\G
3.2.3、验证监控结果
- ProxySQL监控模块的指标都保存在monitor库的log表中
- 在ProxySQL上操作
3.2.3.1、验证:连接是否正常(对connect指标的监控)
在前面可能会有很多connect_error,这是因为没有配置监控信息时的错误,配置后如果connect_error的结果为NULL则表示正常
select * from mysql_server_connect_log;
mysql> select * from mysql_server_connect_log;
+----------------+------+------------------+-------------------------+-------------------------------------------------------------------------+
| hostname | port | time_start_us | connect_success_time_us | connect_error |
+----------------+------+------------------+-------------------------+-------------------------------------------------------------------------+
| 192.168.187.88 | 3307 | 1693479837327821 | 0 | Access denied for user 'monitor'@'192.168.187.88' (using password: YES) |
| 192.168.187.88 | 3307 | 1693480317996720 | 0 | Access denied for user 'monitor'@'192.168.187.88' (using password: YES) |
| 192.168.187.88 | 3309 | 1693480318663673 | 0 | Access denied for user 'monitor'@'192.168.187.88' (using password: YES) |
| 192.168.187.88 | 3309 | 1693480326834127 | 1972 | NULL |
| 192.168.187.88 | 3307 | 1693480327390364 | 1743 | NULL |
| 192.168.187.88 | 3308 | 1693480327946619 | 3763 | NULL |
| 192.168.187.88 | 3308 | 1693480386834006 | 1278 | NULL |
| 192.168.187.88 | 3307 | 1693480387561339 | 1784 | NULL |
| 192.168.187.88 | 3309 | 1693480388288688 | 2812 | NULL |
+----------------+------+------------------+-------------------------+-------------------------------------------------------------------------+
3.2.3.3、验证:心跳信息的监控(对ping指标的监控)
select * from mysql_server_ping_log;
mysql> select * from mysql_server_ping_log;
+----------------+------+------------------+----------------------+-------------------------------------------------------------------------+
| hostname | port | time_start_us | ping_success_time_us | ping_error |
+----------------+------+------------------+----------------------+-------------------------------------------------------------------------+
| 192.168.187.88 | 3308 | 1693479994119722 | 0 | Access denied for user 'monitor'@'192.168.187.88' (using password: YES) |
| 192.168.187.88 | 3307 | 1693479994243661 | 0 | Access denied for user 'monitor'@'192.168.187.88' (using password: YES) |
| 192.168.187.88 | 3309 | 1693480324380010 | 0 | Access denied for user 'monitor'@'192.168.187.88' (using password: YES) |
| 192.168.187.88 | 3307 | 1693480327030572 | 1665 | NULL |
| 192.168.187.88 | 3308 | 1693480327154397 | 1222 | NULL |
| 192.168.187.88 | 3309 | 1693480327278349 | 148 | NULL |
| 192.168.187.88 | 3307 | 1693480337009422 | 155 | NULL |
| 192.168.187.88 | 3309 | 1693480337084814 | 487 | NULL |
4、对ProxySQL中的节点分组
- 节点分组
- writer_hostgroup:写组
- reader_hostgroup:读组
- 设置分组信息,需要修改的是main库中的
mysql_replication_hostgroups
表(组复制则是mysql_group_replication_hostgroups表) - mysql_replication_hostgroups表,该表只有3个字段
- 第1个字段:writer_hostgroup,表示写组
- 第2个字段:reader_hostgroup,表示读组
- 第3个字段:注释字段,可随意写
4.1、查看各mysql server所在的组。
mysql> select hostgroup_id,hostname,port,status,weight from mysql_servers;
+--------------+----------------+------+--------+--------+
| hostgroup_id | hostname | port | status | weight |
+--------------+----------------+------+--------+--------+
| 10 | 192.168.187.88 | 3307 | ONLINE | 1 |
| 10 | 192.168.187.88 | 3308 | ONLINE | 1 |
| 10 | 192.168.187.88 | 3309 | ONLINE | 1 |
+--------------+----------------+------+--------+--------+
3 rows in set (0.01 sec)
3个节点都在hostgroup_id=10的组中。
4.2、设置分组信息
指定写组的id为10,读组的id为20
# 往mysql_replication_hostgroups表插入分组数据
insert into mysql_replication_hostgroups values(10,20,"xx项目--读写分离");
# 查看配置
mysql> select * from mysql_replication_hostgroups\G
*************************** 1. row ***************************
writer_hostgroup: 10
reader_hostgroup: 20
comment: xx项目--读写分离
1 row in set (0.00 sec)
# 将配置加载到RUNTIME,使其可以立马生效,并保存到disk。
load mysql servers to runtime;
save mysql servers to disk;
4.3、查看各mysql server所在的组
一加载,Monitor模块就会开始监控后端的read_only值,当监控到read_only值后,就会按照read_only的值将某些节点自动移动到读/写组。
例如,此处所有节点都在id=10的写组,slave1和slave2都是slave,它们的read_only=1,这两个节点将会移动到id=20的组。如果一开始这3节点都在id=20的读组,那么移动的将是Master节点,会移动到id=10的写组。
mysql> select hostgroup_id,hostname,port,status,weight from mysql_servers;
+--------------+----------------+------+--------+--------+
| hostgroup_id | hostname | port | status | weight |
+--------------+----------------+------+--------+--------+
| 10 | 192.168.187.88 | 3307 | ONLINE | 1 |
| 20 | 192.168.187.88 | 3308 | ONLINE | 1 |
| 20 | 192.168.187.88 | 3309 | ONLINE | 1 |
+--------------+----------------+------+--------+--------+
3 rows in set (0.00 sec)
4.4、查看 read_only 的监控日志
mysql> select * from mysql_server_read_only_log;
+----------------+------+------------------+-----------------+-----------+-------+
| hostname | port | time_start_us | success_time_us | read_only | error |
+----------------+------+------------------+-----------------+-----------+-------+
| 192.168.187.88 | 3308 | 1693482835519118 | 2526 | 1 | NULL |
| 192.168.187.88 | 3307 | 1693482835532971 | 832 | 0 | NULL |
| 192.168.187.88 | 3309 | 1693482835546711 | 921 | 1 | NULL |
| 192.168.187.88 | 3309 | 1693482837018968 | 300 | 1 | NULL |
| 192.168.187.88 | 3307 | 1693482837034545 | 433 | 0 | NULL |
| 192.168.187.88 | 3308 | 1693482837050398 | 445 | 1 | NULL |
| 192.168.187.88 | 3307 | 1693482838518918 | 463 | 0 | NULL |
| 192.168.187.88 | 3309 | 1693482838529343 | 287 | 1 | NULL |
| 192.168.187.88 | 3308 | 1693482838540020 | 255 | 1 | NULL |
| 192.168.187.88 | 3309 | 1693482840019019 | 784 | 1 | NULL |
| 192.168.187.88 | 3307 | 1693482840034368 | 251 | 0 | NULL |
| 192.168.187.88 | 3308 | 1693482840049716 | 685 | 1 | NULL |
| 192.168.187.88 | 3308 | 1693482841519780 | 464 | 1 | NULL |
| 192.168.187.88 | 3309 | 1693482841539763 | 405 | 1 | NULL |
| 192.168.187.88 | 3307 | 1693482841559773 | 432 | 0 | NULL |
| 192.168.187.88 | 3309 | 1693482843019178 | 303 | 1 | NULL |
| 192.168.187.88 | 3308 | 1693482843038091 | 227 | 1 | NULL |
| 192.168.187.88 | 3307 | 1693482843056932 | 653 | 0 | NULL |
4.5、配置replication lag监控
4.5.1、replication lag
Monitor模块会监控后端主机组中各slave的数据是否延迟于master,这个延迟行为称为replication lag
,俗称拖后腿。
如果某个slave节点上的数据比master落后很多(临界值见下文),表示这个slave节点处理速度慢,数据较旧。ProxySQL采用一种称为**自动避开(automatic shunned)**的方式,临时避开这个落后的节点。当ProxySQL避开某节点后,ProxySQL不会把SQL语句路由给这个节点。
4.5.2、ProxySQL有几种情况可能会触发自动避开节点的行为:
- 和后端的连接断开。
- slave落后于master过多。
- 和后端建立连接时,错误次数过多。
- second_behind_master=null时,即slave的SQL线程未运行,或者slave未连接到master。(不过这种自动避开的情况是可控的,见全局变量mysql-monitor_slave_lag_when_null
4.5.3、关于replication lag的内容。
Monitor模块会每隔一段时间(mysql-monitor_replication_lag_interval
)去检查一次拖后腿情况,检测的方式是获取show slave status
中的Seconds_Behind_Master
字段值,然后和mysql_servers
表中max_replication_lag
字段的值比较:
Seconds_Behind_Master < max_replication_lag
:表示落后程度尚在允许范围内。Seconds_Behind_Master > max_replication_lag
:表示落后太多,这样的节点应该避开。
只有传统复制结构的slave节点才需要设置max_replication_lag字段,master无需设置,组复制和galera也无需设置,因为这两种复制结构中show slave status的结果为空。
4.5.4、案例:将读组中的所有节点都设置最多落后于master 10秒钟。
update mysql_servers set max_replication_lag=10 where hostgroup_id=20;
load mysql servers to runtime;
save mysql servers to disk;
需要注意的是,Seconds_Behind_Master的值并不总是可靠的,见
https://dev.mysql.com/doc/refman/5.7/en/show-slave-status.html 。
5、关于主机组和read_only
前面为了将主机组分为读组和写组,特地开启了monitor模块的read_only监控功能,根据read_only的值以及mysql_replication_hostgroup
表中定义的读、写组自动调整节点。
在简单的环境下,这没什么问题。但是想要实现复杂一点的读、写分离,比如写操作路由到hostgroup_id=10的组,读操作分多种情况路由,select1语句路由到hostgroup_id=20的读组,select2语句路由到hostgroup_id=30的组,…。这种情况,想通过monitor模块和mysql_replication_hostgroup表来实现是不可能的,因为mysql_replication_hostgroup表的writer_hostgroup字段是主键,reader_hostgroup字段具有唯一性,它们都是int类型,且不可重复。
mysql_replication_hostgroup表结构
mysql> show create table main.mysql_replication_hostgroups\G
*************************** 1. row ***************************
table: mysql_replication_hostgroups
Create Table: CREATE TABLE mysql_replication_hostgroups(
writer_hostgroup INT CHECK(writer_hostgroup>=0) NOT NULL PRIMARY KEY,
reader_hostgroup INT NOT NULL CHECK(reader_hostgroup<>writer_hostgroup AND reader_hostgroup>0),
comment VARCHAR NOT NULL DEFAULT '', UNIQUE(reader_hostgroup))
1 row in set(0.00 sec)
换句话说,每一个写组只能且必须对应单个读组(经测试,reader_hostgroup
字段可以为空),无法实现hg_id=10是写组,而hg_id=20、hg_id=30同时作为读组。
显然ProxySQL不可能限制的这么死。实际上,完全可以不用定义mysql_replication_hostgroup
表,也不用定义monitor模块的read_only监控(如果没有定义mysql_replication_hostgroup
,read_only
监控会自动停止),这时只能人为控制不要把写操作路由到后端的slave上。
例如:
delete from mysql_replication_hostgroup;
delete from mysql_servers;
insert into mysql_servers(hostgroup_id,hostname,port)values(10,'192.168.187.88',3307);
insert into mysql_servers(hostgroup_id,hostname,port)values(20,'192.168.187.88',3308);
insert into mysql_servers(hostgroup_id,hostname,port)values(30,'192.168.187.88',3309);
# 将配置加载到RUNTIME,使其可以立马生效,并保存到disk。
load mysql servers to runtime;
save mysql servers to disk;
事实上,在实现ProxySQL复杂、高级的路由功能时,都不会通过monitor模块去自动控制读、写组。
6、添加 普通用户
这是应用端 连接ProxySQL(默认6033端口)、ProxySQL连接 后端MySQL时使用一套用户名。
具体看
ProxySQL--基础--3.2--用户--管理用户
# 3、添加 普通用户
6.1、msyql 添加用户(只需master执行即可,会复制给两个slave)
我们需要先在后端MySQL节点添加好相关用户。这里以root和sqlsender两个用户名为例。
# 创建用户
create user sqlsender@'192.168.187.%' identified by '123456';
# 授权
grant all on *.* to root@'192.168.187.%' identified by '123456';
grant all on *.* to sqlsender@'192.168.187.%' identified by '123456';
6.2、ProxySQL 添加用户
配置mysql_users表,将刚才的两个用户添加到该表中。
insert into mysql_users(username,password,default_hostgroup)values('root','123456',10);
insert into mysql_users(username,password,default_hostgroup)values('sqlsender','123456',10);
# 将配置加载到RUNTIME,使其可以立马生效,并保存到disk。
load mysql users to runtime;
save mysql users to disk;
6.3、测试
6.3.1、通过连接来验证
6.3.2、通过查看mysql_users表来验证
select * from mysql_users\G
要保证上面的值为1
6.3.3、通过server_id来验证
使用root用户或者sqlsender用户测试下它们是否能路由到默认的hostgroup_id=10(它是一个写组)读、写数据。
select @@server_id
7、总结
7.1、使用ProxySQL所必须完成的步骤
- 添加MySQL节点
- 监控后端MySQL节点
- 添加 普通用户
这3个步骤虽然需要操作的过程不多,但是涉及的内容还是比较多的。
强烈建议将mysql_servers、mysql_users、mysql_replication_hostgroups
这3个表的所有字段都了解一遍。不仅如此,要熟练使用ProxySQL,还应该对main库中的表的各个字段都比较熟悉,至少要知道它们什么意思。
7.2、步骤总结
7.2.1、添加MySQL节点
# 连接到ProxySQL的管理接口
mysql -uadmin -padmin -P6032 -h127.0.0.1;
insert into mysql_servers(hostgroup_id,hostname,port)values(10,'192.168.187.88',3307);
insert into mysql_servers(hostgroup_id,hostname,port)values(10,'192.168.187.88',3308);
insert into mysql_servers(hostgroup_id,hostname,port)values(10,'192.168.187.88',3309);
# 将配置加载到RUNTIME,使其可以立马生效,并保存到disk。
load mysql servers to runtime;
save mysql servers to disk;
# 查看下各节点是否都是 ONLINE
select * from mysql_servers\G
7.2.2、监控后端MySQL节点
# 进入容器
docker exec -it M1 bash ;
# 进入mysql
mysql -uroot -proot ;
# 在mysql的master 节点上 创建一个监控用户
create user monitor@'192.168.187.%' identified by '123456';
grant replication client on *.* to monitor@'192.168.187.%';
# 在ProxySQL中配置监控用户
# 连接到ProxySQL的管理接口
mysql -uadmin -padmin -P6032 -h127.0.0.1;
set mysql-monitor_username='monitor';
set mysql-monitor_password='123456';
# 配置需要加载到RUNTIME,并保存到disk。
load mysql variables to runtime;
save mysql variables to disk;
# 可以通过下面语句查询
select * from global_variables WHERE variable_name='mysql-monitor_username'\G
# 查看下connect和ping的监控是否正常
select * from mysql_server_connect_log order by time_start_us desc limit 6;
select * from mysql_server_ping_log order by time_start_us desc limit 6;
7.2.3、对ProxySQL中的节点分组
# 往mysql_replication_hostgroups表插入分组数据
insert into mysql_replication_hostgroups values(10,20,"xx项目--读写分离");
# 将配置加载到RUNTIME,使其可以立马生效,并保存到disk。
load mysql servers to runtime;
save mysql servers to disk;
7.2.4、添加 普通用户
# msyql 添加用户(只需master执行即可,会复制给两个slave)
# 创建用户
create user sqlsender@'192.168.187.%' identified by '123456';
# 授权
grant all on *.* to root@'192.168.187.%' identified by '123456';
grant all on *.* to sqlsender@'192.168.187.%' identified by '123456';
# ProxySQL 添加用户
insert into mysql_users(username,password,default_hostgroup)values('root','123456',10);
insert into mysql_users(username,password,default_hostgroup)values('sqlsender','123456',10);
# 将配置加载到RUNTIME,使其可以立马生效,并保存到disk。
load mysql users to runtime;
save mysql users to disk;
# 保证transaction_persistent=1
update mysql_users set transaction_persistent=1 where username='root';
# 将配置加载到RUNTIME,使其可以立马生效,并保存到disk。
load mysql users to runtime;
save mysql users to disk;