proxySQL with MGR

环境信息

hostname IP port role comm ms81 192.168.188.81 3399 master ms82 192.168.188.82 3399 slave ms83 192.168.188.83 3399 slave ms84 192.168.188.84 6033 proxysql&sysbench

  • ProxySQL version 2.0.11-124-g971c15e, codename Truls
  • MySQL 8.0.19 x86_64
  • mysqlsh 8.0.20
  • CentOS 7.8.2003 on Docker

配置MySQL

通过MySQL Shell配置singlePrimary模式MGR

配置用户

mysql> set global super_read_only=0;

mysql> create user mgr@'192.168.188.%' identified by 'mgr';

mysql> grant all privileges on *.* to mgr@'192.168.188.%' with grant option;

mysql> create user kk@'192.168.188.%' identified by 'kk';

mysql> grant all privileges on *.* to kk@'192.168.188.%';

mysql> create user proxy@'192.168.188.%' identified with mysql_native_password by 'proxy';

mysql> grant all privileges on *.* to proxy@'192.168.188.%';

mysql> create user monitor@'192.168.188.%' identified with mysql_native_password by 'monitor';

mysql> grant replication client on *.* to monitor@'192.168.188.%';

mysql> reset master;

mysql> create database kk;

运行proxysql需要的脚本

[13:46:00] root@ms81:/ofiles # mysql -S /data/mysql/mysql3399/tmp/mysql.sock  < addition_to_sys8.sql

#记得授权!
mysql> grant select on sys.gr_member_routing_candidate_status to 'monitor'@'192.168.188.%';
Query OK, 0 rows affected (0.12 sec)

配置ProxySQL

定义并配置proxysql的HostGroups

gid hostgroup 100 read 111 write 122 backup_write 404 offline

mysql> show create table mysql_group_replication_hostgroups\G
*************************** 1. row ***************************
       table: mysql_group_replication_hostgroups
Create Table: CREATE TABLE mysql_group_replication_hostgroups (
    writer_hostgroup INT CHECK (writer_hostgroup>=0) NOT NULL PRIMARY KEY,
    backup_writer_hostgroup INT CHECK (backup_writer_hostgroup>=0 AND backup_writer_hostgroup<>writer_hostgroup) NOT NULL,
    reader_hostgroup INT NOT NULL CHECK (reader_hostgroup<>writer_hostgroup AND backup_writer_hostgroup<>reader_hostgroup AND reader_hostgroup>0),
    offline_hostgroup INT NOT NULL CHECK (offline_hostgroup<>writer_hostgroup AND offline_hostgroup<>reader_hostgroup AND backup_writer_hostgroup<>offline_hostgroup AND offline_hostgroup>=0),
    active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 1,
    max_writers INT NOT NULL CHECK (max_writers >= 0) DEFAULT 1,
    writer_is_also_reader INT CHECK (writer_is_also_reader IN (0,1,2)) NOT NULL DEFAULT 0,
    max_transactions_behind INT CHECK (max_transactions_behind>=0) NOT NULL DEFAULT 0,
    comment VARCHAR,
    UNIQUE (reader_hostgroup),
    UNIQUE (offline_hostgroup),
    UNIQUE (backup_writer_hostgroup))
1 row in set (0.00 sec)

这里没修改  max_writers ,默认为1。 不建议增加,即使是multiPromary模式,proxysql也建议使用单写。
mysql> insert into mysql_group_replication_hostgroups(writer_hostgroup,backup_writer_hostgroup,reader_hostgroup,offline_hostgroup,active) values (111,122,100,404,1);
Query OK, 1 row affected (0.00 sec)

mysql> select * from mysql_group_replication_hostgroups;
+------------------+-------------------------+------------------+-------------------+--------+-------------+-----------------------+-------------------------+---------+
| writer_hostgroup | backup_writer_hostgroup | reader_hostgroup | offline_hostgroup | active | max_writers | writer_is_also_reader | max_transactions_behind | comment |
+------------------+-------------------------+------------------+-------------------+--------+-------------+-----------------------+-------------------------+---------+
| 111              | 122                     | 100              | 404               | 1      | 1           | 0                     | 0                       | NULL    |
+------------------+-------------------------+------------------+-------------------+--------+-------------+-----------------------+-------------------------+---------+
1 row in set (0.00 sec)

添加servers

mysql> show create table mysql_servers\G
*************************** 1. row ***************************
       table: mysql_servers
Create Table: CREATE TABLE mysql_servers (
    hostgroup_id INT CHECK (hostgroup_id>=0) NOT NULL DEFAULT 0,
    hostname VARCHAR NOT NULL,
    port INT CHECK (port >= 0 AND port  port OR gtid_port=0) AND gtid_port >= 0 AND gtid_port = 0 AND weight =0) NOT NULL DEFAULT 1000,
    max_replication_lag INT CHECK (max_replication_lag >= 0 AND max_replication_lag =0) NOT NULL DEFAULT 0,
    comment VARCHAR NOT NULL DEFAULT '',
    PRIMARY KEY (hostgroup_id, hostname, port) )
1 row in set (0.00 sec)

mysql> insert into mysql_servers(hostgroup_id,hostname,port,max_connections) values (100,'192.168.188.81',3399,200);
Query OK, 1 row affected (0.00 sec)

mysql> insert into mysql_servers(hostgroup_id,hostname,port,max_connections) values (100,'192.168.188.82',3399,200);
Query OK, 1 row affected (0.00 sec)

mysql> insert into mysql_servers(hostgroup_id,hostname,port,max_connections) values (100,'192.168.188.83',3399,200);
Query OK, 1 row affected (0.00 sec)

mysql> select hostgroup_id,hostname,port,max_connections from mysql_servers;
+--------------+----------------+------+-----------------+
| hostgroup_id | hostname       | port | max_connections |
+--------------+----------------+------+-----------------+
| 100          | 192.168.188.81 | 3399 | 200             |
| 100          | 192.168.188.82 | 3399 | 200             |
| 100          | 192.168.188.83 | 3399 | 200             |
+--------------+----------------+------+-----------------+
3 rows in set (0.00 sec)

mysql> load mysql servers to run;
Query OK, 0 rows affected (0.01 sec)

mysql> save mysql servers to disk;
Query OK, 0 rows affected (0.83 sec)

添加user

mysql> show create table mysql_users\G
*************************** 1. row ***************************
       table: mysql_users
Create Table: CREATE TABLE mysql_users (
    username VARCHAR NOT NULL,
    password VARCHAR,
    active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 1,
    use_ssl INT CHECK (use_ssl IN (0,1)) NOT NULL DEFAULT 0,
    default_hostgroup INT NOT NULL DEFAULT 0,
    default_schema VARCHAR,
    schema_locked INT CHECK (schema_locked IN (0,1)) NOT NULL DEFAULT 0,
    transaction_persistent INT CHECK (transaction_persistent IN (0,1)) NOT NULL DEFAULT 1,
    fast_forward INT CHECK (fast_forward IN (0,1)) NOT NULL DEFAULT 0,
    backend INT CHECK (backend IN (0,1)) NOT NULL DEFAULT 1,
    frontend INT CHECK (frontend IN (0,1)) NOT NULL DEFAULT 1,
    max_connections INT CHECK (max_connections >=0) NOT NULL DEFAULT 10000,
    comment VARCHAR NOT NULL DEFAULT '',
    PRIMARY KEY (username, backend),
    UNIQUE (username, frontend))
1 row in set (0.00 sec)

mysql> insert into mysql_users(username,password,active,default_hostgroup,default_schema) values ('proxy','proxy',1,100,'kk');
Query OK, 1 row affected (0.00 sec)

mysql> insert into mysql_users(username,password,active,default_hostgroup,default_schema) values ('kk','kk',1,100,'kk');
Query OK, 1 row affected (0.00 sec)

mysql> select * from mysql_users;
+----------+----------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+---------+
| username | password | active | use_ssl | default_hostgroup | default_schema | schema_locked | transaction_persistent | fast_forward | backend | frontend | max_connections | comment |
+----------+----------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+---------+
| proxy    | proxy    | 1      | 0       | 100               | kk             | 0             | 1                      | 0            | 1       | 1        | 10000           |         |
| kk       | kk       | 1      | 0       | 100               | kk             | 0             | 1                      | 0            | 1       | 1        | 10000           |         |
+----------+----------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+---------+
2 rows in set (0.00 sec)

mysql> load mysql users to run;
Query OK, 0 rows affected (0.00 sec)

mysql> save mysql users to disk;
Query OK, 0 rows affected (0.36 sec)

检查一下,可以看到已经根据节点状态进行分组


mysql> select * from monitor.mysql_server_group_replication_log;

mysql> select * from runtime_mysql_servers;
+--------------+----------------+------+-----------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
| hostgroup_id | hostname       | port | gtid_port | status | weight | compression | max_connections | max_replication_lag | use_ssl | max_latency_ms | comment |
+--------------+----------------+------+-----------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
| 100          | 192.168.188.82 | 3399 | 0         | ONLINE | 1      | 0           | 200             | 0                   | 0       | 0              |         |
| 111          | 192.168.188.81 | 3399 | 0         | ONLINE | 1      | 0           | 200             | 0                   | 0       | 0              |         |
| 100          | 192.168.188.83 | 3399 | 0         | ONLINE | 1      | 0           | 200             | 0                   | 0       | 0              |         |
+--------------+----------------+------+-----------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
3 rows in set (0.01 sec)

添加规则前做一次性能测试

[15:37:26] root@ms84:~ # sysbench /usr/share/sysbench/oltp_read_write.lua  --db-driver=mysql --mysql-host=192.168.188.84 --mysql-port=6033  --mysql-user=kk --mysql-password=kk --mysql-db=kk --table-size=50000 prepare
sysbench 1.0.17 (using system LuaJIT 2.0.4)

Creating table 'sbtest1'...

FATAL: mysql_drv_query() returned error 1290 (The MySQL server is running with the --super-read-only option so it cannot execute this statement) for query 'CREATE TABLE sbtest1(
  id INTEGER NOT NULL AUTO_INCREMENT,
  k INTEGER DEFAULT '0' NOT NULL,
  c CHAR(120) DEFAULT '' NOT NULL,
  pad CHAR(60) DEFAULT '' NOT NULL,
  PRIMARY KEY (id)
) /*! ENGINE = innodb */ '
FATAL: `sysbench.cmdline.call_command' function failed: /usr/share/sysbench/oltp_common.lua:197: SQL error, errno = 1290, state = 'HY000': The MySQL server is running with the --super-read-only option so it cannot execute this statement

&#x770B;&#x6765;&#x9700;&#x8981;&#x4FEE;&#x6539;&#x4E00;&#x4E0B;&#xFF0C;&#x4E0D;&#x7136;&#x627E;&#x4E0D;&#x5230;rw&#x670D;&#x52A1;&#x5668;&#x2026;&#x2026; &#x9ED8;&#x8BA4;&#x90FD;&#x53D1;&#x7ED9;&#x53EA;&#x8BFB;&#x7EC4;&#x4E86;&#x3002;

&#x8FD9;&#x5757;&#x5B9E;&#x9A8C;&#x4E2D;&#x53D1;&#x73B0;&#x4E86;&#x4E2A;&#x95EE;&#x9898;&#xFF0C;sysbench&#x901A;&#x8FC7;proxysql&#x7684;&#x670D;&#x52A1;&#x7AEF;&#x53E3;&#x8FDE;&#x63A5;&#x540E;&#xFF0C;&#x65E0;&#x6CD5;&#x8FDB;&#x884C;&#x4EFB;&#x4F55;&#x64CD;&#x4F5C;&#xFF1A;
mysql> show tables;
ERROR 1045 (28000): Access denied for user 'kk'@'ms84.net188' (using password: YES)
&#x53EF;&#x4EE5;&#x53D1;&#x73B0;&#xFF0C;&#x7528;&#x6237;&#x88AB;&#x89E3;&#x6790;&#x6210;proxysql&#x7684;&#x57DF;&#x540D;&#x6765;&#x6E90;&#x4E86;&#xFF0C;&#x800C;&#x5B9E;&#x9645;&#x4E0A;&#x5BF9;kk&#x7528;&#x6237;&#x7684;&#x6388;&#x6743;&#x505A;&#x7684;&#x662F; kk@'192.168.188.%',
&#x67E5;&#x770B;&#x4E86;&#x4E00;&#x4E0B;MySQL&#x7684;&#x53C2;&#x6570;&#x6587;&#x4EF6;&#xFF0C;&#x539F;&#x56E0;&#x4E3A;&#xFF1A;
mysql> show global variables like '%reso%';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| skip_name_resolve | OFF   |
+-------------------+-------+
1 row in set (0.01 sec)
&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;&#x4E3A;1&#xFF0C; &#x6216;&#x91CD;&#x65B0;&#x5EFA;&#x7ACB;&#x7528;&#x6237; kk@'%' &#xFF0C;&#x5728;&#x672C;&#x6B21;&#x5B9E;&#x9A8C;&#x91CC;&#xFF0C;&#x7531;&#x4E8E;&#x8BBE;&#x8BA1;&#x7684;&#x662F;&#x6240;&#x6709;&#x8BBF;&#x95EE;&#x901A;&#x8FC7;proxysql&#xFF0C;proxysql&#x4EE5;kk&#x7528;&#x6237;&#x4E0E;MySQL MGR&#x901A;&#x4FE1;
&#x56E0;&#x6B64;&#x5728;&#x8FD9;&#x91CC;&#x6211;&#x53E6;&#x5916;&#x5EFA;&#x7ACB;&#x4E86;&#x7528;&#x6237;'kk'@'ms84.net188'&#xFF0C;&#x5E76;&#x6388;&#x6743;&#x3002;
&#x518D;&#x6B21;&#x901A;&#x8FC7;&#x5176;&#x5B83;IP&#x4F7F;&#x7528;proxysql&#x7684;&#x670D;&#x52A1;&#x7AEF;&#x53E3;&#x767B;&#x5F55;&#x540E;&#xFF0C;&#x67E5;&#x770B;&#x5F53;&#x524D;&#x7528;&#x6237;&#x4E3A;&#xFF1A;
mysql> select current_user();
+----------------+
| current_user() |
+----------------+
| kk@ms84.net188 |
+----------------+
1 row in set (0.00 sec)
&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;&#x65E0;&#x8BBA;&#x53D1;&#x8D77;&#x8FDE;&#x63A5;&#x8BF7;&#x6C42;&#x7684;client&#x5728;&#x54EA;&#x91CC;&#xFF0C;current_user &#x90FD;&#x662F;proxysql&#x7684;domain&#xFF0C;&#x8FD9;&#x4E5F;&#x9A8C;&#x8BC1;&#x4E86;&#x524D;&#x9762;&#x7684;&#x731C;&#x6D4B;&#x3002;

proxysql&#x4FEE;&#x6539;&#xFF1A;
mysql> update mysql_users set default_hostgroup=111 where username='kk';
Query OK, 1 row affected (0.00 sec)

mysql> load mysql users to run;
Query OK, 0 rows affected (0.00 sec)

[15:39:01] root@ms84:~ # sysbench /usr/share/sysbench/oltp_read_write.lua  --db-driver=mysql --mysql-host=192.168.188.84 --mysql-port=6033  --mysql-user=kk --mysql-password=kk --mysql-db=kk --table-size=50000 prepare
sysbench 1.0.17 (using system LuaJIT 2.0.4)

Creating table 'sbtest1'...

Inserting 50000 records into 'sbtest1'
Creating a secondary index on 'sbtest1'...

[15:40:57] root@ms84:~ # sysbench /usr/share/sysbench/oltp_read_write.lua  --db-driver=mysql --mysql-host=192.168.188.84 --mysql-port=6033  --mysql-user=kk --mysql-password=kk --mysql-db=kk --table-size=50000 run
sysbench 1.0.17 (using system LuaJIT 2.0.4)

Running the test with following options:
Number of threads: 1
Initializing random number generator from current time

Initializing worker threads...

Threads started!

SQL statistics:
    queries performed:
        read:                            714
        write:                           204
        other:                           102
        total:                           1020
    transactions:                        51     (5.00 per sec.)
    queries:                             1020   (100.03 per sec.)
    ignored errors:                      0      (0.00 per sec.)
    reconnects:                          0      (0.00 per sec.)

General statistics:
    total time:                          10.1929s
    total number of events:              51

Latency (ms):
         min:                                  104.38
         avg:                                  199.83
         max:                                  444.15
         95th percentile:                      297.92
         sum:                                10191.23

Threads fairness:
    events (avg/stddev):           51.0000/0.00
    execution time (avg/stddev):   10.1912/0.00

mysql> select hostgroup,digest, digest_text,count_star from stats.stats_mysql_query_digest;
+-----------+--------------------+--------------------------------------------------------------------+------------+
| hostgroup | digest             | digest_text                                                        | count_star |
+-----------+--------------------+--------------------------------------------------------------------+------------+
| 111       | 0xE52A0A0210634DAC | INSERT INTO sbtest1 (id, k, c, pad) VALUES (?, ?, ?, ?)            | 52         |
| 111       | 0xE365BEB555319B9E | DELETE FROM sbtest1 WHERE id=?                                     | 52         |
| 111       | 0xFB239BC95A23CA36 | UPDATE sbtest1 SET c=? WHERE id=?                                  | 52         |
| 111       | 0xC19480748AE79B4B | SELECT DISTINCT c FROM sbtest1 WHERE id BETWEEN ? AND ? ORDER BY c | 52         |
| 111       | 0xAC80A5EA0101522E | SELECT c FROM sbtest1 WHERE id BETWEEN ? AND ? ORDER BY c          | 52         |
| 111       | 0xC198E52BCCB481C7 | UPDATE sbtest1 SET k=k+? WHERE id=?                                | 52         |
| 111       | 0xDBF868B2AA296BC5 | SELECT SUM(k) FROM sbtest1 WHERE id BETWEEN ? AND ?                | 52         |
| 111       | 0x290B92FD743826DA | SELECT c FROM sbtest1 WHERE id BETWEEN ? AND ?                     | 52         |
| 111       | 0xBF001A0C13781C1D | SELECT c FROM sbtest1 WHERE id=?                                   | 511        |
| 111       | 0x695FBF255DBEB0DD | COMMIT                                                             | 52         |
| 111       | 0xFAD1519E4760CBDE | BEGIN                                                              | 52         |
+-----------+--------------------+--------------------------------------------------------------------+------------+
11 rows in set (0.01 sec)

做完全的读写分离规则

&#x5728;&#x8FD9;&#x91CC;&#x505A;&#x5B8C;&#x5168;&#x7684;&#x8BFB;&#x5199;&#x5206;&#x79BB;.

&#x53EF;&#x4EE5;&#x770B;&#x51FA;&#x6765;&#x5728;&#x4E00;&#x53F0;&#x7269;&#x7406;server&#x4E0A;&#x8FD9;&#x6837;&#x641E;&#x662F;&#x6709;&#x635F;&#x5931;&#x7684;&#xFF0C;&#x54C8;&#x54C8;
mysql> insert into mysql_query_rules(rule_id,active,match_pattern,destination_hostgroup,apply) values (1,1,'^SELECT.*FOR UPDATE$',111,1);
Query OK, 1 row affected (0.00 sec)

mysql> insert into mysql_query_rules(rule_id,active,match_pattern,destination_hostgroup,apply) values (2,1,'^SELECT.*',100,1);
Query OK, 1 row affected (0.00 sec)

mysql> select * from mysql_query_rules;
+---------+--------+----------+------------+--------+-------------+------------+------------+--------+--------------+----------------------+----------------------+--------------+---------+-----------------+-----------------------+-----------+--------------------+---------------+-----------+---------+---------+-------+-------------------+----------------+------------------+-----------+--------+-------------+-----------+---------------------+-----+-------+---------+
| rule_id | active | username | schemaname | flagIN | client_addr | proxy_addr | proxy_port | digest | match_digest | match_pattern        | negate_match_pattern | re_modifiers | flagOUT | replace_pattern | destination_hostgroup | cache_ttl | cache_empty_result | cache_timeout | reconnect | timeout | retries | delay | next_query_flagIN | mirror_flagOUT | mirror_hostgroup | error_msg | OK_msg | sticky_conn | multiplex | gtid_from_hostgroup | log | apply | comment |
+---------+--------+----------+------------+--------+-------------+------------+------------+--------+--------------+----------------------+----------------------+--------------+---------+-----------------+-----------------------+-----------+--------------------+---------------+-----------+---------+---------+-------+-------------------+----------------+------------------+-----------+--------+-------------+-----------+---------------------+-----+-------+---------+
| 1       | 1      | NULL     | NULL       | 0      | NULL        | NULL       | NULL       | NULL   | NULL         | ^SELECT.*FOR UPDATE$ | 0                    | CASELESS     | NULL    | NULL            | 111                   | NULL      | NULL               | NULL          | NULL      | NULL    | NULL    | NULL  | NULL              | NULL           | NULL             | NULL      | NULL   | NULL        | NULL      | NULL                | NULL | 1     | NULL    |
| 2       | 1      | NULL     | NULL       | 0      | NULL        | NULL       | NULL       | NULL   | NULL         | ^SELECT.*            | 0                    | CASELESS     | NULL    | NULL            | 100                   | NULL      | NULL               | NULL          | NULL      | NULL    | NULL    | NULL  | NULL              | NULL           | NULL             | NULL      | NULL   | NULL        | NULL      | NULL                | NULL | 1     | NULL    |
+---------+--------+----------+------------+--------+-------------+------------+------------+--------+--------------+----------------------+----------------------+--------------+---------+-----------------+-----------------------+-----------+--------------------+---------------+-----------+---------+---------+-------+-------------------+----------------+------------------+-----------+--------+-------------+-----------+---------------------+-----+-------+---------+
2 rows in set (0.00 sec)

mysql> load mysql query rules to run;
Query OK, 0 rows affected (0.00 sec)

mysql> save mysql query rules to disk;
Query OK, 0 rows affected (0.47 sec)

mysql> select hostgroup,digest, digest_text,count_star from stats.stats_mysql_query_digest_reset;

[15:51:54] root@ms84:~ # sysbench /usr/share/sysbench/oltp_read_write.lua  --db-driver=mysql --mysql-host=192.168.188.84 --mysql-port=6033  --mysql-user=kk --mysql-password=kk --mysql-db=kk --table-size=50000 run
sysbench 1.0.17 (using system LuaJIT 2.0.4)

Running the test with following options:
Number of threads: 1
Initializing random number generator from current time

Initializing worker threads...

Threads started!

SQL statistics:
    queries performed:
        read:                            672
        write:                           192
        other:                           96
        total:                           960
    transactions:                        48     (4.79 per sec.)
    queries:                             960    (95.87 per sec.)
    ignored errors:                      0      (0.00 per sec.)
    reconnects:                          0      (0.00 per sec.)

General statistics:
    total time:                          10.0099s
    total number of events:              48

Latency (ms):
         min:                                  104.58
         avg:                                  208.51
         max:                                  458.81
         95th percentile:                      331.91
         sum:                                10008.26

Threads fairness:
    events (avg/stddev):           48.0000/0.00
    execution time (avg/stddev):   10.0083/0.00

mysql> select hostgroup,digest, digest_text,count_star from stats.stats_mysql_query_digest;
+-----------+--------------------+--------------------------------------------------------------------+------------+
| hostgroup | digest             | digest_text                                                        | count_star |
+-----------+--------------------+--------------------------------------------------------------------+------------+
| 111       | 0xE52A0A0210634DAC | INSERT INTO sbtest1 (id, k, c, pad) VALUES (?, ?, ?, ?)            | 49         |
| 111       | 0xFB239BC95A23CA36 | UPDATE sbtest1 SET c=? WHERE id=?                                  | 49         |
| 111       | 0xC198E52BCCB481C7 | UPDATE sbtest1 SET k=k+? WHERE id=?                                | 49         |
| 100       | 0xC19480748AE79B4B | SELECT DISTINCT c FROM sbtest1 WHERE id BETWEEN ? AND ? ORDER BY c | 49         |
| 100       | 0xAC80A5EA0101522E | SELECT c FROM sbtest1 WHERE id BETWEEN ? AND ? ORDER BY c          | 49         |
| 111       | 0xE365BEB555319B9E | DELETE FROM sbtest1 WHERE id=?                                     | 49         |
| 100       | 0x290B92FD743826DA | SELECT c FROM sbtest1 WHERE id BETWEEN ? AND ?                     | 49         |
| 100       | 0xBF001A0C13781C1D | SELECT c FROM sbtest1 WHERE id=?                                   | 481        |
| 100       | 0xDBF868B2AA296BC5 | SELECT SUM(k) FROM sbtest1 WHERE id BETWEEN ? AND ?                | 49         |
| 111       | 0x695FBF255DBEB0DD | COMMIT                                                             | 49         |
| 111       | 0xFAD1519E4760CBDE | BEGIN                                                              | 49         |
+-----------+--------------------+--------------------------------------------------------------------+------------+
11 rows in set (0.01 sec)

看一下MGR做failover时,proxysql的状态。

  • 当前MGR状态
 MySQL  192.168.188.81:3399 ssl  JS > cl.status()
{
    "clusterName": "kk",
    "defaultReplicaSet": {
        "name": "default",
        "primary": "ms81:3399",
        "ssl": "REQUIRED",
        "status": "OK",
        "statusText": "Cluster is ONLINE and can tolerate up to ONE failure.",
        "topology": {
            "ms81:3399": {
                "address": "ms81:3399",
                "mode": "R/W",
                "readReplicas": {},
                "replicationLag": null,
                "role": "HA",
                "status": "ONLINE",
                "version": "8.0.19"
            },
            "ms82:3399": {
                "address": "ms82:3399",
                "mode": "R/O",
                "readReplicas": {},
                "replicationLag": "00:00:00.317335",
                "role": "HA",
                "status": "ONLINE",
                "version": "8.0.19"
            },
            "ms83:3399": {
                "address": "ms83:3399",
                "mode": "R/O",
                "readReplicas": {},
                "replicationLag": "00:00:00.227030",
                "role": "HA",
                "status": "ONLINE",
                "version": "8.0.19"
            }
        },
        "topologyMode": "Single-Primary"
    },
    "groupInformationSourceMember": "ms81:3399"
}

  • 当前proxysql mysql_servers状态
mysql>  select * from runtime_mysql_servers;
+--------------+----------------+------+-----------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
| hostgroup_id | hostname       | port | gtid_port | status | weight | compression | max_connections | max_replication_lag | use_ssl | max_latency_ms | comment |
+--------------+----------------+------+-----------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
| 100          | 192.168.188.83 | 3399 | 0         | ONLINE | 1      | 0           | 200             | 0                   | 0       | 0              |         |
| 111          | 192.168.188.81 | 3399 | 0         | ONLINE | 1      | 0           | 200             | 0                   | 0       | 0              |         |
| 100          | 192.168.188.82 | 3399 | 0         | ONLINE | 1      | 0           | 200             | 0                   | 0       | 0              |         |
+--------------+----------------+------+-----------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
3 rows in set (0.01 sec)

  • 将当前master重启,再查看proxysql mysql_servers
master:
mysql> shutdown ;
Query OK, 0 rows affected (0.00 sec)

mysql> mysql>  select * from runtime_mysql_servers;
+--------------+----------------+------+-----------+---------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
| hostgroup_id | hostname       | port | gtid_port | status  | weight | compression | max_connections | max_replication_lag | use_ssl | max_latency_ms | comment |
+--------------+----------------+------+-----------+---------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
| 100          | 192.168.188.83 | 3399 | 0         | ONLINE  | 1      | 0           | 200             | 0                   | 0       | 0              |         |
| 404          | 192.168.188.81 | 3399 | 0         | SHUNNED | 1      | 0           | 200             | 0                   | 0       | 0              |         |
| 111          | 192.168.188.82 | 3399 | 0         | ONLINE  | 1      | 0           | 200             | 0                   | 0       | 0              |         |
+--------------+----------------+------+-----------+---------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
3 rows in set (0.00 sec)

  • 重启master ,再查看
master
[16:12:33] root@ms81:~ # mysqld --defaults-file=/data/mysql/mysql3399/my3399.cnf &

&#x4F7F;&#x7528;MySQL shell&#x6784;&#x5EFA;&#x7684;MGR &#xFF0C;&#x5728;&#x8282;&#x70B9;&#x91CD;&#x542F;&#x540E;&#x4F1A;&#x81EA;&#x52A8;&#x542F;&#x52A8;GR

mysql>  select * from runtime_mysql_servers;
+--------------+----------------+------+-----------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
| hostgroup_id | hostname       | port | gtid_port | status | weight | compression | max_connections | max_replication_lag | use_ssl | max_latency_ms | comment |
+--------------+----------------+------+-----------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
| 100          | 192.168.188.83 | 3399 | 0         | ONLINE | 1      | 0           | 200             | 0                   | 0       | 0              |         |
| 111          | 192.168.188.82 | 3399 | 0         | ONLINE | 1      | 0           | 200             | 0                   | 0       | 0              |         |
| 100          | 192.168.188.81 | 3399 | 0         | ONLINE | 1      | 0           | 200             | 0                   | 0       | 0              |         |
+--------------+----------------+------+-----------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
3 rows in set (0.00 sec)

个个原创文章

欢迎讨论
https://www.cnblogs.com/konggg/
欢迎转载收藏,转载请注明来源,谢谢支持!

Original: https://www.cnblogs.com/konggg/p/13571589.html
Author: 孔个个
Title: proxySQL with MGR

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/621250/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • 0812Java核心技术卷(1)随笔

    自增运算符与自减运算符 这些运算符改变了变量的值,所以它的操作数不能是数值。例如4++就是一条非法语句不建议在其他表达式内部使用++,因为这样会降低代码可读性,产生bug Orig…

    数据库 2023年6月14日
    0103
  • .NetCore2.0引用DLL报System.InvalidOperationException: Can not find compilation library location for package ‘XXX’

    .NET CORE 2.0 MVC项目引用类库出现:System.InvalidOperationException: Can not find compilation libra…

    数据库 2023年6月14日
    0105
  • java扫描某个包下的所有java类并加载

    最近在学习java的反射和注解,实际情景中需要扫描某个包下的所有java类,然后使用类加载器加载类。 基本思路,获得程序的路径扫描src下某个包内的子包和java类,实现也比较简单…

    数据库 2023年6月11日
    0109
  • [SQLServer]NetCore中将SQLServer数据库备份为Sql脚本

    描述: 最近写项目收到了一个需求, 就是将 SQL Server数据库备份为Sql脚本, 如果是My Sql之类的还好说, 但是在网上搜了一大堆, 全是教你怎么操作 SSMS的, …

    数据库 2023年6月9日
    0100
  • 关于SQL语句的执行顺序

    首先,要清楚在一select语句中都会用到哪些关键字: 其次,要知道每执行一步就会生成一个对应的虚拟表: 了解这两点,然后看看执行的顺序。 [En] Understand thes…

    数据库 2023年5月24日
    082
  • Java架构师电商项目(220h):1-1 整体架构概述

    2022 Flag:学完这门 220h Java架构师电商项目视频课学习笔记将持续更新…… ; 大型网站特点 高并发 高可用 大数据 迭代周期短 用户量庞大…

    数据库 2023年6月6日
    093
  • 升级JDK8的坎坷之路

    为更好的适应JAVA技术的发展,使用更先进及前沿的技术。所以推出将我们现在使用的JDK1.6(1.7)及tomcat6(7)升级至JDK1.8及tomcat8,使我们的系统获得更好…

    数据库 2023年6月6日
    0100
  • DASCTF 熟悉的猫

    压缩包需要密码,不是伪加密,爆破也爆不出来,下面的kdbx文件搜了一下可以用keepass ;打开,但是居然还是需要密码 那这个只能是弱口令或者爆破了,但是纯手工肯定不可取,找了很…

    数据库 2023年6月11日
    081
  • 23种设计模式之分类总结

    关于设计模式的学习要告一段落了,学习的这一路上,也收到了不少小伙伴的留言,以及点赞给了我莫大的鼓励,我在这里谢谢大家的鼓励。。。 我会再接再厉,嘿嘿。。。 以上的话虽是真心话,但是…

    数据库 2023年6月6日
    0283
  • leetcode 114. Flatten Binary Tree to Linked List 二叉树展开为链表(简单)

    一、题目大意 给你二叉树的根结点 root ,请你将它展开为一个单链表: 展开后的单链表应该同样使用 TreeNode ,其中 right 子指针指向链表中下一个结点,而左子指针始…

    数据库 2023年6月16日
    0107
  • FastDFS安装和简介详细总结

    1、fastDFS简介 1 FastDFS是用c语言编写的一款开源的分布式文件系统。 2 FastDFS为互联网量身定制,充分考虑了冗余备份、负载均衡、线性扩容等机制,并注重高可用…

    数据库 2023年6月14日
    0113
  • mysql8使用tmpfs内存磁盘当内存数据库的配置方法

    内存关系数据库没有找到开源好用的,很多都是商用。虽然mysql有memory引擎,但写是整体锁表,没法用。 一直想将mysql放入内存中,搜索n次资料,没找到合适的,可能之前思路不…

    数据库 2023年5月24日
    0111
  • mysql约束

    一、表约束 PK主键约束(索引)唯一约束 非空 默认值 在关系数据库,一个表中,只能有一个主键(Primary Key),有些数据库没有pk,系统报出错误。 在myql数据库,建立…

    数据库 2023年6月9日
    085
  • MySQL处理Java客户端连接

    在MySQL里面往往有一个主线程,这是单线程,它不断的循环查看是否有socket是否有读写事件,如果有读写事件,再从线程池里面找个工作线程处理这个socket的读写事件,完事之后工…

    数据库 2023年6月11日
    0115
  • MySQL学习笔记-day02

    select distinct job from emp;# distinct关键字去除重复记录。 结果: +———–+ | job | +———–+ …

    数据库 2023年6月11日
    095
  • 1291. 顺次数

    我们定义「顺次数」为:每一位上的数字都比前一位上的数字大 1 的整数。 请你返回由 [low, high] 范围内所有顺次数组成的 有序 列表(从小到大排序)。 示例 1: 输出:…

    数据库 2023年6月16日
    077
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球