-- 1. 清空旧配置DELETEFROM mysql_servers;DELETEFROM mysql_users;DELETEFROM mysql_query_rules;-- 2. 添加后端MySQL节点INSERTINTO mysql_servers(hostgroup_id,hostname,port,weight,max_connections,max_replication_lag)VALUES-- 写组:主库(10,'192.168.10.10',3306,1000,2000,3),-- 读组:两台从库,权重一致,延迟超过3秒自动下线(20,'192.168.10.11',3306,100,2000,3),(20,'192.168.10.12',3306,100,2000,3);-- 3. 监控账号配置SET mysql_monitor_username='proxy_monitor';SET mysql_monitor_password='Monitor@123';SET mysql_monitor_connect_timeout=1000;SET mysql_monitor_ping_timeout=500;SET mysql_monitor_replication_lag_threshold=3;-- 4. 读写分离路由规则-- rule1:SELECT ... FOR UPDATE 走主库INSERTINTO mysql_query_rules(rule_id,active,match_pattern,destination_hostgroup,apply,comment)VALUES(1,1,'^SELECT .*FOR UPDATE$',10,0,'行锁查询强制主库');-- rule2:普通SELECT走读库INSERTINTO mysql_query_rules(rule_id,active,match_pattern,destination_hostgroup,apply,comment)VALUES(2,1,'^SELECT',20,1,'普通查询负载均衡从库');-- rule3:其余DML/DDL全部走主库INSERTINTO mysql_query_rules(rule_id,active,match_pattern,destination_hostgroup,apply,comment)VALUES(3,1,'.',10,1,'增删改建表走主库');-- 5. 业务访问账号INSERTINTO mysql_users(username,password,default_hostgroup,transaction_persistent,max_connections)VALUES('app_user','App@123',10,1,1500);-- 6. 加载生效+持久化LOAD MYSQL SERVERS TO RUNTIME;LOAD MYSQL VARIABLES TO RUNTIME;LOAD MYSQL QUERY RULES TO RUNTIME;LOAD MYSQL USERS TO RUNTIME;SAVE MYSQL SERVERS TODISK;SAVE MYSQL VARIABLES TODISK;SAVE MYSQL QUERY RULES TODISK;SAVE MYSQL USERS TODISK;-- 查看校验SELECT hostgroup_id,hostname,status,weight,max_replication_lag FROM mysql_servers;SELECT rule_id,match_pattern,destination_hostgroup FROM mysql_query_rules;SELECT username,default_hostgroup FROM mysql_users;