MySQL Router 当前配置为:
[logger]
level = INFO
[routing:instance1]
bind_address = 0.0.0.0
bind_port = 7001
destinations = 172.20.1.29:18251
routing_strategy = first-available
[routing:instance2]
bind_address = 0.0.0.0
bind_port = 7002
destinations = 172.20.1.25:18251
routing_strategy = first-available
[routing:instance3]
bind_address = 0.0.0.0
bind_port = 7003
destinations = 172.20.1.15:18251
routing_strategy = first-available
[routing:instance4]
bind_address = 0.0.0.0
bind_port = 7004
destinations = 172.20.1.16:18251
routing_strategy = first-available
[routing:instance5]
bind_address = 0.0.0.0
bind_port = 7005
destinations = 172.20.1.19:18251
routing_strategy = first-available
[routing:instance6]
bind_address = 0.0.0.0
bind_port = 7006
destinations = 172.20.1.20:18251
routing_strategy = first-available
[routing:instance7]
bind_address = 0.0.0.0
bind_port = 7007
destinations = 172.20.1.17:18251
routing_strategy = first-available
[routing:instance8]
bind_address = 0.0.0.0
bind_port = 7008
destinations = 172.20.1.21:18251
routing_strategy = first-available
MySQL Router 配置核心逻辑 : 8 个独立端口(7001-7008),每个端口一对一转发 到固定的 MySQL 后端(first-available = 仅连接第一个目标,失败则不可用),无负载均衡、无故障转移。
目标:
- 配置与 MySQL Router 等价的 ProxySQL(2.6.5),端口、后端、行为完全一致。
- 业务侧零改动,直接复用原连接地址和端口。
ProxySQL 配置如下:
datadir="/var/lib/proxysql"
admin_variables=
{
admin_credentials="admin:admin"
mysql_ifaces="0.0.0.0:6032"
refresh_interval=2000
}
mysql_variables=
{
threads=4
max_connections=2048
default_query_delay=0
default_query_timeout=36000000
have_compress=true
poll_timeout=2000
interfaces="0.0.0.0:7001;0.0.0.0:7002;0.0.0.0:7003;0.0.0.0:7004;0.0.0.0:7005;0.0.0.0:7006;0.0.0.0:7007;0.0.0.0:7008"
default_schema="information_schema"
stacksize=1048576
idle_timeout=28800
connection_max_age_ms=0
mysql_forward_authentication=1
}
# 必须把所有八个实例中用到的所有用户名都加上
# 因为 mysql_forward_authentication=1,这里密码可以随便写(只是个占位符),实际验证在后端 MySQL 中。
# 但用户必须配,用户名必须唯一。连接哪个实例就在哪个做认证
mysql_users =
(
{ username="wxy", password="x" },
{ username="u1", password="x" }
)
mysql_servers =
(
{ address="172.20.1.29", port=18251, hostgroup=1, status="ONLINE", weight=1 },
{ address="172.20.1.25", port=18251, hostgroup=2, status="ONLINE", weight=1 },
{ address="172.20.1.15", port=18251, hostgroup=3, status="ONLINE", weight=1 },
{ address="172.20.1.16", port=18251, hostgroup=4, status="ONLINE", weight=1 },
{ address="172.20.1.19", port=18251, hostgroup=5, status="ONLINE", weight=1 },
{ address="172.20.1.20", port=18251, hostgroup=6, status="ONLINE", weight=1 },
{ address="172.20.1.17", port=18251, hostgroup=7, status="ONLINE", weight=1 },
{ address="172.20.1.21", port=18251, hostgroup=8, status="ONLINE", weight=1 }
)
mysql_query_rules =
(
{ rule_id=1, active=1, port=7001, destination_hostgroup=1, apply=1 },
{ rule_id=2, active=1, port=7002, destination_hostgroup=2, apply=1 },
{ rule_id=3, active=1, port=7003, destination_hostgroup=3, apply=1 },
{ rule_id=4, active=1, port=7004, destination_hostgroup=4, apply=1 },
{ rule_id=5, active=1, port=7005, destination_hostgroup=5, apply=1 },
{ rule_id=6, active=1, port=7006, destination_hostgroup=6, apply=1 },
{ rule_id=7, active=1, port=7007, destination_hostgroup=7, apply=1 },
{ rule_id=8, active=1, port=7008, destination_hostgroup=8, apply=1 }
)
只需要做 3 步:
- 先把旧进程杀掉(防止端口冲突)
pkill proxysql
- 清空旧数据(必须!让新配置生效)
rm -rf /var/lib/proxysql/*
- 用命令直接启动
proxysql -c /etc/proxysql.cnf
✅ 启动完成!全部配置自动加载!
验证是否启动成功
ss -tulpn | grep proxysql
能看到 7001 ~ 7008 都在监听,就说明正常了。