实验主机
Proxysql:192.168.0.30主机上基于yum安装proxysql [root@centos6 ~ 20:21:05]#cat <<EOF | tee /etc/yum.repos.d/proxysql.repo > [proxysql_repo] > name= ProxySQL YUM repository > baseurl=http://repo.proxysql.com/ProxySQL/proxysql-1.4.x/centos/\$releasever > gpgcheck=1 > gpgkey=http://repo.proxysql.com/ProxySQL/repo_pub_key > EOF
查看yum源配置是否成功 [root@centos6 ~ 20:08:36]#mysql -uadmin -padmin -P6032 -h127.0.0.1
MySQL [(none)]> insert into mysql_servers(hostgroup_id,hostname,port) values(10,'192.168.0.17',3306); MySQL[(none)]>insert into mysql_servers(hostgroup_id,hostname,port) values(10,'192.168.0.20',3306); MySQL [(none)]> load mysql servers to runtime; MySQL [(none)]> save mysql servers to disk;
MariaDB [(none)]> grant replication client on *.* to monitor@'192.168.0.%' identified by '123'; MariaDB [(none)]> flush privileges;
MySQL [(none)]> set mysql-monitor_username='monitor'; MySQL [(none)]> set mysql-monitor_password='123'; MySQL [(none)]> load mysql variables to runtime; MySQL [(none)]> save mysql variables to disk;
MySQL> select * from mysql_server_connect_log;
MySQL> select * from mysql_server_ping_log;
MySQL> select * from mysql_server_read_only_log; MySQL> select * from mysql_server_replication_lag_log;
设置分组信息: MySQL> insert into mysql_replication_hostgroups values(10,20,"test");
读组proxysql会自动根据my.cnf的read_only来判断你是否是读组自动更改 MySQL> load mysql servers to runtime; MySQL> save mysql servers to disk;
MySQL> select hostgroup_id,hostname,port,status,weight from mysql_servers;
MariaDB [(none)]> grant all on *.* to sqluser@'192.168.0.%' identified by '123';
MariaDB [(none)]> flush privileges; MariaDB [(none)]> grant all on *.* to sqluser@'192.168.0.%' identified by '123'; MariaDB [(none)]> flush privileges;
MySQL> insert into mysql_users(username,password,default_hostgroup) values('sqluser','123',10); MySQL> load mysql users to runtime; MySQL> save mysql users to disk;
mysql -usqluser –p123 -P6033 -h127.0.0.1 -e 'select @@server_id' mysql -usqluser –p123 -P6033 -h127.0.0.1 -e 'create database testdb' mysql -usqluser –p123 testdb -P6033 -h127.0.0.1 -e 'create table t(id int)'
MySQL> insert into mysql_query_rules (rule_id,active,match_digest,destination_hostgroup,apply)VALUES (1,1,'^SELECT.*FOR UPDATE$',10,1),(2,1,'^SELECT',20,1); MySQL> load mysql query rules to runtime; MySQL> save mysql query rules to disk;
注意:因ProxySQL根据rule_id顺序进行规则匹配,select ... for update规则的rule_id必须要小于普通的select规则的rule_id mysql -usqluser -pmagedu -P6033 -h127.0.0.1 -e 'select @@server_id'
mysql -usqluser -pmagedu -P6033 -h127.0.0.1 -e 'start transaction;select @@server_id;commit;select @@server_id' 路由的信息:查询stats库中的stats_mysql_query_digest表 MySQL > SELECT hostgroup hg,sum_time, count_star, digest_text FROM stats_mysql_query_digest ORDER BY sum_time DESC; (责任编辑:IT) |