目录
[1. 在 MySQL 实例创建用户](#1. 在 MySQL 实例创建用户)
[2. 主从状态规范](#2. 主从状态规范)
[四、ProxySQL 配置(Admin 端口 6032)](#四、ProxySQL 配置(Admin 端口 6032))
[1. 连接 ProxySQL Admin](#1. 连接 ProxySQL Admin)
[2. 配置监控账号(全局生效)](#2. 配置监控账号(全局生效))
[3. 添加 MySQL 服务器到 mysql_servers](#3. 添加 MySQL 服务器到 mysql_servers)
[4. 配置复制 HostGroup](#4. 配置复制 HostGroup)
[5. 配置业务用户](#5. 配置业务用户)
[6. 配置查询路由规则](#6. 配置查询路由规则)
[7. 加载所有配置到运行时、持久化到磁盘](#7. 加载所有配置到运行时、持久化到磁盘)
[1. 查看服务器分组与状态](#1. 查看服务器分组与状态)
[2. 查看复制 HostGroup 绑定](#2. 查看复制 HostGroup 绑定)
[3. 查看查询规则](#3. 查看查询规则)
[4. 通过 monitor 库查看后端服务器健康状态](#4. 通过 monitor 库查看后端服务器健康状态)
[5. 测试连接与路由(业务端口 6033)](#5. 测试连接与路由(业务端口 6033))
[六、扩展到 N 组主从](#六、扩展到 N 组主从)
要在一个 ProxySQL 实例里代理多组独立 MySQL 主从,核心思路是:给每组主从分配唯一、不重叠的 HostGroup(写组 + 读组),用 mysql_replication_hostgroups 绑定每组的写 / 读组,再通过用户默认组 + 查询路由规则隔离流量。下面从规划、配置、验证、故障切换四步完整落地。
一、环境说明
- MySQL 版本 8.0.22
- ProxySQL 版本 2.6.5(最稳定。代理多套主机组时,2.7.3 有 bug)
- 第一组主从:
- 主: 172.18.3.122:18251
- 从1:172.18.3.232:18251
- 从2:172.18.4.109:18251
- 第二组主从:
- 主: 172.18.3.232:18252
- 从1:172.18.3.122:18252
- 从2:172.18.4.109:18252
- 每组主从都启用半同步复制、GTID、AUTO_POSITION
已经在 ProxySQL 中配置了第一组主从的主机组和查询规则:
sql
Admin> SELECT hostgroup_id, status, hostname, port, weight, max_connections, max_replication_lag FROM mysql_servers;
+--------------+--------+--------------+-------+--------+-----------------+---------------------+
| hostgroup_id | status | hostname | port | weight | max_connections | max_replication_lag |
+--------------+--------+--------------+-------+--------+-----------------+---------------------+
| 1 | ONLINE | 172.18.4.109 | 18251 | 1 | 1000 | 60 |
| 2 | ONLINE | 172.18.3.122 | 18251 | 1 | 1000 | 60 |
| 1 | ONLINE | 172.18.3.122 | 18251 | 1 | 1000 | 60 |
| 1 | ONLINE | 172.18.3.232 | 18251 | 1 | 1000 | 60 |
+--------------+--------+--------------+-------+--------+-----------------+---------------------+
4 rows in set (0.00 sec)
Admin> SELECT hostgroup_id, status, hostname, port, weight, max_connections, max_replication_lag FROM runtime_mysql_servers;
+--------------+--------+--------------+-------+--------+-----------------+---------------------+
| hostgroup_id | status | hostname | port | weight | max_connections | max_replication_lag |
+--------------+--------+--------------+-------+--------+-----------------+---------------------+
| 1 | ONLINE | 172.18.3.122 | 18251 | 1 | 1000 | 60 |
| 2 | ONLINE | 172.18.3.122 | 18251 | 1 | 1000 | 60 |
| 2 | ONLINE | 172.18.3.232 | 18251 | 1 | 1000 | 60 |
| 2 | ONLINE | 172.18.4.109 | 18251 | 1 | 1000 | 60 |
+--------------+--------+--------------+-------+--------+-----------------+---------------------+
4 rows in set (0.00 sec)
Admin> SELECT rule_id, active, match_digest, destination_hostgroup, apply FROM mysql_query_rules ORDER BY rule_id;
+---------+--------+-----------------------------+-----------------------+-------+
| rule_id | active | match_digest | destination_hostgroup | apply |
+---------+--------+-----------------------------+-----------------------+-------+
| 1 | 1 | ^INSERT | 1 | 1 |
| 2 | 1 | ^UPDATE | 1 | 1 |
| 3 | 1 | ^DELETE | 1 | 1 |
| 4 | 1 | ^REPLACE | 1 | 1 |
| 5 | 1 | ^MERGE | 1 | 1 |
| 10 | 1 | ^CREATE | 1 | 1 |
| 11 | 1 | ^ALTER | 1 | 1 |
| 12 | 1 | ^DROP | 1 | 1 |
| 13 | 1 | ^TRUNCATE | 1 | 1 |
| 14 | 1 | ^RENAME | 1 | 1 |
| 15 | 1 | ^GRANT | 1 | 1 |
| 16 | 1 | ^REVOKE | 1 | 1 |
| 20 | 1 | ^SELECT.*FOR UPDATE | 1 | 1 |
| 21 | 1 | ^SELECT.*LOCK IN SHARE MODE | 1 | 1 |
| 100 | 1 | ^SELECT | 2 | 1 |
+---------+--------+-----------------------------+-----------------------+-------+
15 rows in set (0.00 sec)
下面在 ProxySQL 中添加第二组 MySQL 主从实例,同样实现这组的读写分离和读负载均衡(一写三读)。
二、核心规划
关键:每组独立 HostGroup。每组主从必须用专属、不重复的写组 (writer HG)、读组 (reader HG),避免互相干扰。
- 集群 A(业务 A):写组 = 1,读组 = 2
- 集群 B(业务 B):写组 = 3,读组 = 4
三、前置准备
1. 在 MySQL 实例创建用户
(1)监控用户
ProxySQL 健康检查用:
sql
-- 在 172.18.3.232:18252 执行
CREATE USER monitor IDENTIFIED BY 'monitor';
GRANT USAGE, REPLICATION CLIENT ON *.* TO monitor;
(2)业务用户
ProxySQL 连接集群用。注意 ProxySQL 不允许相同用户名同时给多个集群用,因此这里注意不同集群的业务用户不要重名。
sql
CREATE USER wxy_2 IDENTIFIED BY '123456';
GRANT all ON *.* TO wxy_2;
2. 主从状态规范
- 主库:read_only=0, super_read_only=0(可写)
- 从库:read_only=1, super_read_only=1(只读)
ProxySQL 靠 read_only 自动识别主/从、切换 HostGroup。
四、ProxySQL 配置(Admin 端口 6032)
1. 连接 ProxySQL Admin
bash
mysql -u admin -padmin -h 127.0.0.1 -P6032 --prompt='ProxySQL Admin> '
2. 配置监控账号(全局生效)
这里已经在代理第一组主从时配置好:
sql
Admin> select * from global_variables where variable_name in ('mysql-monitor_username','mysql-monitor_password');
+------------------------+----------------+
| variable_name | variable_value |
+------------------------+----------------+
| mysql-monitor_password | monitor |
| mysql-monitor_username | monitor |
+------------------------+----------------+
2 rows in set (0.00 sec)
如果需要新配则执行:
sql
UPDATE global_variables SET variable_value='monitor' WHERE variable_name='mysql-monitor_username';
UPDATE global_variables SET variable_value='monitor' WHERE variable_name='mysql-monitor_password';
LOAD MYSQL VARIABLES TO RUNTIME;
SAVE MYSQL VARIABLES TO DISK;
3. 添加 MySQL 服务器到 mysql_servers
添加第二组实例。
sql
-- 集群B:主(172.18.3.232:18252)、从1(172.18.3.122:18252)、从2(172.18.4.109:18252)
INSERT INTO mysql_servers(hostgroup_id,hostname,port,comment) VALUES (3,'172.18.3.232',18252,'Cluster2-Master');
INSERT INTO mysql_servers(hostgroup_id,hostname,port,comment) VALUES (3,'172.18.3.122',18252,'Cluster2-Slave1');
INSERT INTO mysql_servers(hostgroup_id,hostname,port,comment) VALUES (3,'172.18.4.109',18252,'Cluster2-Slave2');
4. 配置复制 HostGroup
核心:绑定每组写/读组。
sql
-- 集群B:写3、读4
INSERT INTO mysql_replication_hostgroups(writer_hostgroup,reader_hostgroup,check_type,comment)
VALUES (3,4,'read_only','Cluster2-Replication');
-- 手动把主库加入读组 4(永久生效,不会被自动模式覆盖)
INSERT INTO mysql_servers (hostgroup_id, hostname, port)
VALUES (4, '172.18.3.232', 18252);
LOAD MYSQL SERVERS TO RUNTIME;
SAVE MYSQL SERVERS TO DISK;
确认生效:
sql
Admin> SELECT hostgroup_id, hostname, port, status
-> FROM runtime_mysql_servers
-> ORDER BY hostgroup_id, hostname;
+--------------+--------------+-------+--------+
| hostgroup_id | hostname | port | status |
+--------------+--------------+-------+--------+
| 1 | 172.18.3.122 | 18251 | ONLINE |
| 2 | 172.18.3.122 | 18251 | ONLINE |
| 2 | 172.18.3.232 | 18251 | ONLINE |
| 2 | 172.18.4.109 | 18251 | ONLINE |
| 3 | 172.18.3.232 | 18252 | ONLINE |
| 4 | 172.18.3.122 | 18252 | ONLINE |
| 4 | 172.18.3.232 | 18252 | ONLINE |
| 4 | 172.18.4.109 | 18252 | ONLINE |
+--------------+--------------+-------+--------+
8 rows in set (0.00 sec)
5. 配置业务用户
按集群隔离,默认路由到对应写组。
sql
-- 业务B用户:默认走集群B写组3
INSERT INTO mysql_users(username,password,default_hostgroup,comment)
VALUES ('wxy_2','123456',3,'ClusterB-User');
LOAD MYSQL USERS TO RUNTIME;
SAVE MYSQL USERS TO DISK;
6. 配置查询路由规则
读写分离,每组独立。
sql
UPDATE mysql_users SET default_hostgroup=3 where username='wxy_2';
LOAD MYSQL USERS TO RUNTIME;
sql
-- 插入生产级完整规则
INSERT INTO mysql_query_rules (rule_id,active,match_digest,destination_hostgroup,apply)
VALUES
-- 所有写操作 DML
(31,1,'^INSERT',3,1),
(32,1,'^UPDATE',3,1),
(33,1,'^DELETE',3,1),
(34,1,'^REPLACE',3,1),
(35,1,'^MERGE',3,1),
-- 所有 DDL 操作
(40,1,'^CREATE',3,1),
(41,1,'^ALTER',3,1),
(42,1,'^DROP',3,1),
(43,1,'^TRUNCATE',3,1),
(44,1,'^RENAME',3,1),
(45,1,'^GRANT',3,1),
(46,1,'^REVOKE',3,1),
-- 锁查询强制主库
(50,1,'^SELECT.*FOR UPDATE',3,1),
(51,1,'^SELECT.*LOCK IN SHARE MODE',3,1),
-- 普通查询走读组 3台负载
(200,1,'^SELECT',4,1);
-- 一定要绑定用户
update mysql_query_rules set username='wxy' where destination_hostgroup in (1,2);
update mysql_query_rules set username='wxy_2' where destination_hostgroup in (3,4);
-- 加载并保存
LOAD MYSQL QUERY RULES TO RUNTIME;
SAVE MYSQL QUERY RULES TO DISK;
7. 加载所有配置到运行时、持久化到磁盘
sql
LOAD MYSQL VARIABLES TO RUNTIME;
LOAD MYSQL SERVERS TO RUNTIME;
LOAD MYSQL USERS TO RUNTIME;
LOAD MYSQL QUERY RULES TO RUNTIME;
SAVE MYSQL VARIABLES TO DISK;
SAVE MYSQL SERVERS TO DISK;
SAVE MYSQL USERS TO DISK;
SAVE MYSQL QUERY RULES TO DISK;
五、验证配置(关键检查项)
1. 查看服务器分组与状态
sql
Admin> SELECT hostgroup_id,hostname,port,status,comment FROM mysql_servers ORDER BY hostgroup_id;
+--------------+--------------+-------+--------+-----------------+
| hostgroup_id | hostname | port | status | comment |
+--------------+--------------+-------+--------+-----------------+
| 1 | 172.18.3.122 | 18251 | ONLINE | |
| 1 | 172.18.3.232 | 18251 | ONLINE | |
| 1 | 172.18.4.109 | 18251 | ONLINE | |
| 2 | 172.18.3.122 | 18251 | ONLINE | |
| 3 | 172.18.3.122 | 18252 | ONLINE | Cluster2-Slave1 |
| 3 | 172.18.3.232 | 18252 | ONLINE | Cluster2-Master |
| 3 | 172.18.4.109 | 18252 | ONLINE | Cluster2-Slave2 |
| 4 | 172.18.3.232 | 18252 | ONLINE | |
+--------------+--------------+-------+--------+-----------------+
8 rows in set (0.00 sec)
Admin> SELECT hostgroup_id,hostname,port,status,comment FROM runtime_mysql_servers ORDER BY hostgroup_id;
+--------------+--------------+-------+--------+-----------------+
| hostgroup_id | hostname | port | status | comment |
+--------------+--------------+-------+--------+-----------------+
| 1 | 172.18.3.122 | 18251 | ONLINE | |
| 2 | 172.18.3.122 | 18251 | ONLINE | |
| 2 | 172.18.3.232 | 18251 | ONLINE | |
| 2 | 172.18.4.109 | 18251 | ONLINE | |
| 3 | 172.18.3.232 | 18252 | ONLINE | Cluster2-Master |
| 4 | 172.18.3.122 | 18252 | ONLINE | Cluster2-Slave1 |
| 4 | 172.18.3.232 | 18252 | ONLINE | |
| 4 | 172.18.4.109 | 18252 | ONLINE | Cluster2-Slave2 |
+--------------+--------------+-------+--------+-----------------+
8 rows in set (0.01 sec)
- 主库应在写组 (1/3)、read_only=0
- 从库应在读组 (2/4)、read_only=1
- 状态应为ONLINE
2. 查看复制 HostGroup 绑定
sql
Admin> SELECT * FROM mysql_replication_hostgroups;
+------------------+------------------+------------+----------------------+
| writer_hostgroup | reader_hostgroup | check_type | comment |
+------------------+------------------+------------+----------------------+
| 1 | 2 | read_only | cluster1 |
| 3 | 4 | read_only | Cluster2-Replication |
+------------------+------------------+------------+----------------------+
2 rows in set (0.00 sec)
3. 查看查询规则
sql
ProxySQL Admin> select rule_id,active,match_digest,destination_hostgroup,apply,username from runtime_mysql_query_rules;
+---------+--------+-----------------------------+-----------------------+-------+----------+
| rule_id | active | match_digest | destination_hostgroup | apply | username |
+---------+--------+-----------------------------+-----------------------+-------+----------+
| 1 | 1 | ^INSERT | 1 | 1 | wxy |
| 2 | 1 | ^UPDATE | 1 | 1 | wxy |
| 3 | 1 | ^DELETE | 1 | 1 | wxy |
| 4 | 1 | ^REPLACE | 1 | 1 | wxy |
| 5 | 1 | ^MERGE | 1 | 1 | wxy |
| 10 | 1 | ^CREATE | 1 | 1 | wxy |
| 11 | 1 | ^ALTER | 1 | 1 | wxy |
| 12 | 1 | ^DROP | 1 | 1 | wxy |
| 13 | 1 | ^TRUNCATE | 1 | 1 | wxy |
| 14 | 1 | ^RENAME | 1 | 1 | wxy |
| 15 | 1 | ^GRANT | 1 | 1 | wxy |
| 16 | 1 | ^REVOKE | 1 | 1 | wxy |
| 20 | 1 | ^SELECT.*FOR UPDATE | 1 | 1 | wxy |
| 21 | 1 | ^SELECT.*LOCK IN SHARE MODE | 1 | 1 | wxy |
| 31 | 1 | ^INSERT | 3 | 1 | wxy_2 |
| 32 | 1 | ^UPDATE | 3 | 1 | wxy_2 |
| 33 | 1 | ^DELETE | 3 | 1 | wxy_2 |
| 34 | 1 | ^REPLACE | 3 | 1 | wxy_2 |
| 35 | 1 | ^MERGE | 3 | 1 | wxy_2 |
| 40 | 1 | ^CREATE | 3 | 1 | wxy_2 |
| 41 | 1 | ^ALTER | 3 | 1 | wxy_2 |
| 42 | 1 | ^DROP | 3 | 1 | wxy_2 |
| 43 | 1 | ^TRUNCATE | 3 | 1 | wxy_2 |
| 44 | 1 | ^RENAME | 3 | 1 | wxy_2 |
| 45 | 1 | ^GRANT | 3 | 1 | wxy_2 |
| 46 | 1 | ^REVOKE | 3 | 1 | wxy_2 |
| 50 | 1 | ^SELECT.*FOR UPDATE | 3 | 1 | wxy_2 |
| 51 | 1 | ^SELECT.*LOCK IN SHARE MODE | 3 | 1 | wxy_2 |
| 100 | 1 | ^SELECT | 2 | 1 | wxy |
| 200 | 1 | ^SELECT | 4 | 1 | wxy_2 |
+---------+--------+-----------------------------+-----------------------+-------+----------+
30 rows in set (0.00 sec)
4. 通过 monitor 库查看后端服务器健康状态
sql
ProxySQL Admin> SELECT * FROM monitor.mysql_server_connect_log ORDER BY time_start_us DESC LIMIT 10;
+--------------+-------+------------------+-------------------------+---------------+
| hostname | port | time_start_us | connect_success_time_us | connect_error |
+--------------+-------+------------------+-------------------------+---------------+
| 172.18.3.122 | 18251 | 1777270548379729 | 571 | NULL |
| 172.18.4.109 | 18252 | 1777270548371076 | 953 | NULL |
| 172.18.3.232 | 18252 | 1777270548362346 | 854 | NULL |
| 172.18.3.122 | 18252 | 1777270548353708 | 462 | NULL |
| 172.18.4.109 | 18251 | 1777270548344983 | 1033 | NULL |
| 172.18.3.232 | 18251 | 1777270548336322 | 819 | NULL |
| 172.18.3.232 | 18252 | 1777270546381347 | 750 | NULL |
| 172.18.4.109 | 18252 | 1777270546372332 | 917 | NULL |
| 172.18.3.232 | 18251 | 1777270546363212 | 780 | NULL |
| 172.18.3.122 | 18252 | 1777270546354110 | 496 | NULL |
+--------------+-------+------------------+-------------------------+---------------+
10 rows in set (0.00 sec)
5. 测试连接与路由(业务端口 6033)
在 ProxySQL 所在机器执行:
bash
mysql -uwxy_2 -p123456 -h127.0.0.1 -P6033
这是业务入口,所有测试都走这里。同时打开 ProxySQL 管理窗口:
bash
mysql -u admin -padmin -h 127.0.0.1 -P6032 --prompt 'ProxySQL Admin> '
(1)读写分离
sql
-- 写请求必须走主库(hostgroup 3)
CREATE DATABASE test_proxysql;
USE test_proxysql;
CREATE TABLE t(id INT);
INSERT INTO t VALUES (1);
UPDATE t SET id=2;
DELETE FROM t WHERE id=2;
在管理端查看流量分布:
sql
ProxySQL Admin> SELECT hostgroup, count_star, last_seen, digest_text
-> FROM stats_mysql_query_digest
-> ORDER BY last_seen DESC;
+-----------+------------+------------+----------------------------------+
| hostgroup | count_star | last_seen | digest_text |
+-----------+------------+------------+----------------------------------+
| 3 | 1 | 1777270718 | INSERT INTO t VALUES (?) |
| 3 | 1 | 1777270718 | show tables |
| 3 | 1 | 1777270718 | DELETE FROM t WHERE id=? |
| 3 | 1 | 1777270718 | UPDATE t SET id=? |
| 3 | 1 | 1777270718 | show databases |
| 3 | 1 | 1777270718 | CREATE TABLE t(id INT) |
| 4 | 1 | 1777270718 | SELECT DATABASE() |
| 3 | 1 | 1777270718 | CREATE DATABASE test_proxysql |
| 3 | 1 | 1777270693 | select @@version_comment limit ? |
+-----------+------------+------------+----------------------------------+
9 rows in set (0.00 sec)
读写分离 100% 正确,手动执行的所有写操作,全部 → hostgroup=3(主库);手动执行的读操作:SELECT DATABASE() → hostgroup=4(读组)。
- 执行的 6 条全部查到了。
- 多出来的是系统自动 SQL,完全正常。
- 读写分离正常工作。
(2)读负载均衡
bash
[mysql@kxvv-yz-mysqlproxy~]$mysql -uwxy_2 -p123456 -h127.0.0.1 -P6033 -e "SELECT @@server_id;"
mysql: [Warning] Using a password on the command line interface can be insecure.
+-------------+
| @@server_id |
+-------------+
| 10918252 |
+-------------+
[mysql@kxvv-yz-mysqlproxy~]$mysql -uwxy_2 -p123456 -h127.0.0.1 -P6033 -e "SELECT @@server_id;"
mysql: [Warning] Using a password on the command line interface can be insecure.
+-------------+
| @@server_id |
+-------------+
| 23218252 |
+-------------+
[mysql@kxvv-yz-mysqlproxy~]$mysql -uwxy_2 -p123456 -h127.0.0.1 -P6033 -e "SELECT @@server_id;"
mysql: [Warning] Using a password on the command line interface can be insecure.
+-------------+
| @@server_id |
+-------------+
| 10918252 |
+-------------+
[mysql@kxvv-yz-mysqlproxy~]$mysql -uwxy_2 -p123456 -h127.0.0.1 -P6033 -e "SELECT @@server_id;"
mysql: [Warning] Using a password on the command line interface can be insecure.
+-------------+
| @@server_id |
+-------------+
| 10918252 |
+-------------+
[mysql@kxvv-yz-mysqlproxy~]$mysql -uwxy_2 -p123456 -h127.0.0.1 -P6033 -e "SELECT @@server_id;"
mysql: [Warning] Using a password on the command line interface can be insecure.
+-------------+
| @@server_id |
+-------------+
| 12218252 |
+-------------+
[mysql@kxvv-yz-mysqlproxy~]$mysql -uwxy_2 -p123456 -h127.0.0.1 -P6033 -e "SELECT @@server_id;"
mysql: [Warning] Using a password on the command line interface can be insecure.
+-------------+
| @@server_id |
+-------------+
| 10918252 |
+-------------+
[mysql@kxvv-yz-mysqlproxy~]$mysql -uwxy_2 -p123456 -h127.0.0.1 -P6033 -e "SELECT @@server_id;"
mysql: [Warning] Using a password on the command line interface can be insecure.
+-------------+
| @@server_id |
+-------------+
| 12218252 |
+-------------+
[mysql@kxvv-yz-mysqlproxy~]$mysql -uwxy_2 -p123456 -h127.0.0.1 -P6033 -e "SELECT @@server_id;"
mysql: [Warning] Using a password on the command line interface can be insecure.
+-------------+
| @@server_id |
+-------------+
| 10918252 |
+-------------+
[mysql@kxvv-yz-mysqlproxy~]$mysql -uwxy_2 -p123456 -h127.0.0.1 -P6033 -e "SELECT @@server_id;"
mysql: [Warning] Using a password on the command line interface can be insecure.
+-------------+
| @@server_id |
+-------------+
| 12218252 |
+-------------+
[mysql@kxvv-yz-mysqlproxy~]$mysql -uwxy_2 -p123456 -h127.0.0.1 -P6033 -e "SELECT @@server_id;"
mysql: [Warning] Using a password on the command line interface can be insecure.
+-------------+
| @@server_id |
+-------------+
| 10918252 |
+-------------+
[mysql@kxvv-yz-mysqlproxy~]$
手动单 IP 测试,看不到轮询。即使在权重均为 1 的情况下,ProxySQL 也无法实现严格的"1-2-3-1-2-3..."轮询顺序。这并非配置错误,而是由ProxySQL内部连接处理机制决定的。具体说明参见"https://blog.csdn.net/wzy0623/article/details/160352639?#t42"。
六、扩展到 N 组主从
- 新增一组:分配新的唯一写组、读组(如 5、6)
- 插入 mysql_servers(写组 5、读组 6)
- 插入 mysql_replication_hostgroups(5,6)
- 新增业务用户、默认组 = 5
- 新增查询规则,路由 SELECT 到 6
- 加载保存配置
七、关键注意事项
- HostGroup 必须全局唯一:每组写 / 读组不能与其他组重复,这是多集群隔离的基础。
- 监控账号统一:所有 MySQL 实例用同一个 monitor 用户,简化维护。
- read_only 是自动识别核心:主从切换必须正确设置 read_only/super_read_only。
- 故障转移:ProxySQL 仅做自动路由切换,不执行 MySQL 主从提升。通过自定义脚本可以实现对应用透明的主从自动失败切换,实例参见"https://blog.csdn.net/wzy0623/article/details/160409298"。
- 版本兼容:ProxySQL 2.6.5 + MySQL 8.0.22 完全兼容,注意 MySQL 8 密码插件应配置为 mysql_native_password。