ProxySQL安装
· 阅读需 6 分钟
安装
cat <<EOF | tee /etc/yum.repos.d/proxysql.repo
[proxysql_repo]
name= ProxySQL YUM repository
baseurl=https://repo.proxysql.com/ProxySQL/proxysql-2.1.x/centos/\$releasever
gpgcheck=1
gpgkey=https://repo.proxysql.com/ProxySQL/repo_pub_key
EOF
yum install proxysql -y
添加mysql集群节点
提示
同一个节点可以存在多个hostgroup里
mysql -u admin -padmin -h 127.0.0.1 -P 6032
INSERT INTO mysql_servers(hostgroup_id, hostname, port, use_ssl) VALUES (0,'192.168.70.71',3306,1);
INSERT INTO mysql_servers(hostgroup_id, hostname, port, use_ssl) VALUES (0,'192.168.70.72',3306,1);
INSERT INTO mysql_servers(hostgroup_id, hostname, port, use_ssl) VALUES (0,'192.168.70.73',3306,1);
# 保存配置
LOAD MYSQL SERVERS TO RUNTIME;
SAVE MYSQL SERVERS TO DISK;
查看
SELECT * FROM mysql_servers;
添加客户端登录用户
注意
用户必须在mysql节点中存在账号密码一样,目前proxysql只支持mysql_native_password密码插件,在mysql节点添加用户时候必须指定插件为mysql_native_password。
# mysql节点中执行
CREATE USER 'root'@'%' IDENTIFIED WITH mysql_native_password by '123456';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
通过定义default_hostgroup我们指定用户应该默认连接到指定相同hostgroup_id后端服务器
# proxysql中执行
INSERT INTO mysql_users (username,password,default_hostgroup) VALUES ('root',MYSQL_NATIVE_PASSWORD('123456'),0);
LOAD MYSQL USERS TO RUNTIME;
SAVE MYSQL USERS TO DISK;
查看
SELECT * FROM mysql_users;