iis服务器助手广告广告
返回顶部
首页 > 资讯 > 数据库 >proxysql配置读写分离策略和权重调整一例
  • 685
分享到

proxysql配置读写分离策略和权重调整一例

2024-04-02 19:04:59 685人浏览 独家记忆
摘要

操作系统:Centos release 6.9  主库: 192.168.140.51 从库1: 192.168.140.52   read_only=on 从库2: 19

操作系统Centos release 6.9 

主库: 192.168.140.51

从库1: 192.168.140.52   read_only=on

从库2: 192.168.16.150   read_only=on

proxysql中间件: 192.168.140.52



配置读写分离策略,要求主库写,两个从库读,把所有select开头的SQL语句全部分配到编号为20的读组里,select for update或update操作分配到编号为10的写组里:

Mysql> insert into mysql_query_rules(active,match_pattern,destination_hostgroup,apply) values(1,'^SELECT.*FOR UPDATE$',10,1);

Query OK, 1 row affected (0.00 sec)


mysql> insert into mysql_query_rules(active,match_pattern,destination_hostgroup,apply) values(1,'^SELECT',20,1);

Query OK, 1 row affected (0.00 sec)


mysql> load mysql query rules to runtime;

Query OK, 0 rows affected (0.00 sec)


mysql> save mysql query rules to disk;


#mysql -udsf -pdsf -h 192.168.140.52 -P 6033        (备注:6033为中间件对外访问端口号)

mysql: [Warning] Using a passWord on the command line interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 8

Server version: 5.5.30 (ProxySQL)


Copyright (c) 2000, 2018, oracle and/or its affiliates. All rights reserved.


Oracle is a reGIStered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> use test

Reading table infORMation for completion of table and column names

You can turn off this feature to get a quicker startup with -A


Database changed


mysql> select * from t;     

Empty set (0.00 sec)


mysql> select * from t1;

Empty set (0.00 sec)


mysql> select * from t1 for update;

Empty set (0.00 sec)


mysql> select * from test limit 10;

+------+----------------------------------------------------------------------------------+

| a    | b                                                                                |

+------+----------------------------------------------------------------------------------+

| NULL | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |

| NULL | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |

| NULL | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |

| NULL | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |

| NULL | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |

| NULL | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |

| NULL | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |

| NULL | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |

| NULL | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |

| NULL | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |

+------+----------------------------------------------------------------------------------+

10 rows in set (0.00 sec)



mysql> select * from test_new limit 3;

+------+----------+

| a    | b        |

+------+----------+

| NULL | chenfeng |

| NULL | chenfeng |

| NULL | chenfeng |

+------+----------+

3 rows in set (0.00 sec)


mysql> update test_new set b='dsf';

Query OK, 60000 rows affected (1.80 sec)

Rows matched: 60000  Changed: 60000  Warnings: 0



读写分离测试:

mysql>  select * from stats_mysql_query_digest;

+-----------+--------------------+----------+--------------------+----------------------------------+------------+------------+------------+----------+----------+----------+

| hostgroup | schemaname         | username | digest             | digest_text                      | count_star | first_seen | last_seen  | sum_time | min_time | max_time |

+-----------+--------------------+----------+--------------------+----------------------------------+------------+------------+------------+----------+----------+----------+

| 20        | test               | dsf      | 0x0E68CEFBB3EF90B1 | select count(?) from test_new    | 1          | 1539068254 | 1539068254 | 76155    | 76155    | 76155    |

| 10        | test               | dsf      | 0x2FC734A8D89E32FC | desc qianzhui                    | 1          | 1539068239 | 1539068239 | 2325     | 2325     | 2325     |

| 10        | test               | dsf      | 0x90923742A873577C | update test_new set b=?          | 1          | 1539068280 | 1539068280 | 1802294  | 1802294  | 1802294  |

| 20        | test               | dsf      | 0x620B328FE9D6D71A | SELECT DATABASE()                | 1          | 1539068226 | 1539068226 | 1429     | 1429     | 1429     |

| 10        | information_schema | dsf      | 0xAE231F4D14BA1FD6 | KILL QUERY ?                     | 1          | 1539067381 | 1539067381 | 2162     | 2162     | 2162     |

| 10        | information_schema | dsf      | 0x226CD90D52A2BA0B | select @@version_comment limit ? | 5          | 1539065258 | 1539067396 | 0        | 0        | 0        |

| 10        | test               | dsf      | 0x376A8E5E76BBC701 | desc test_new                    | 1          | 1539068244 | 1539068244 | 2217     | 2217     | 2217     |

| 20        | test               | dsf      | 0x38DF1D37B3136F42 | select * from test               | 2          | 1539067275 | 1539067381 | 62259    | 28837    | 33422    |

| 10        | information_schema | dsf      | 0x82A12D4C4E7B0A28 | select @@hostname                | 1          | 1539065302 | 1539065302 | 1375     | 1375     | 1375     |

| 10        | information_schema | dsf      | 0x02033E45904D3DF0 | show databases                   | 1          | 1539067215 | 1539067215 | 3012     | 3012     | 3012     |

| 20        | test               | dsf      | 0xDAFAB555D432CB6F | select * from test_new limit ?   | 1          | 1539068264 | 1539068264 | 769      | 769      | 769      |

| 20        | information_schema | dsf      | 0x620B328FE9D6D71A | SELECT DATABASE()                | 3          | 1539067262 | 1539067399 | 6154     | 851      | 4429     |

| 20        | test               | dsf      | 0xD8BDF2ED80FC3809 | select * from test limit ?       | 1          | 1539067425 | 1539067425 | 850      | 850      | 850      |

| 10        | information_schema | dsf      | 0xA4D993880D70C4D9 | show slave hosts                 | 1          | 1539065258 | 1539065258 | 6351     | 6351     | 6351     |

| 20        | test               | dsf      | 0x3765930C7143F468 | select * from t1                 | 4          | 1539067272 | 1539068207 | 5724     | 587      | 2876     |

| 10        | test               | dsf      | 0x02033E45904D3DF0 | show databases                   | 3          | 1539067262 | 1539067399 | 8745     | 1974     | 4136     |

| 20        | test               | dsf      | 0xDB236914B7E74FBD | select * from t                  | 3          | 1539067269 | 1539067403 | 5831     | 720      | 3521     |

| 10        | test               | dsf      | 0x5A680F86B3D8FB2B | select * from t1 for update      | 1          | 1539068209 | 1539068209 | 1921     | 1921     | 1921     |

| 10        | test               | dsf      | 0x99531AEFF718C501 | show tables                      | 5          | 1539067262 | 1539068228 | 8407     | 1155     | 2173     |

+-----------+--------------------+----------+--------------------+----------------------------------+------------+------------+------------+----------+----------+----------+

19 rows in set (0.00 sec)



调整读写分离权重:

mysql> update mysql_servers set weight=5 where hostname='192.168.16.150';

Query OK, 1 row affected (0.00 sec)


mysql> select * from mysql_servers;

+--------------+----------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+

| hostgroup_id | hostname       | port | status | weight | compression | max_connections | max_replication_lag | use_ssl | max_latency_ms | comment |

+--------------+----------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+

| 10           | 192.168.140.51 | 3306 | ONLINE | 1      | 0           | 1000            | 0                   | 0       | 0              |         |

| 20           | 192.168.16.150 | 3306 | ONLINE | 5      | 0           | 1000            | 0                   | 0       | 0              |         |

| 20           | 192.168.140.52 | 3306 | ONLINE | 1      | 0           | 1000            | 0                   | 0       | 0              |         |

+--------------+----------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+

3 rows in set (0.00 sec)


mysql> load mySQL Servers to runtime;

Query OK, 0 rows affected (0.00 sec)


mysql> save mysql servers to disk;

Query OK, 0 rows affected (0.23 sec)


mysql> select * from mysql_servers;

+--------------+----------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+

| hostgroup_id | hostname       | port | status | weight | compression | max_connections | max_replication_lag | use_ssl | max_latency_ms | comment |

+--------------+----------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+

| 10           | 192.168.140.51 | 3306 | ONLINE | 1      | 0           | 1000            | 0                   | 0       | 0              |         |

| 20           | 192.168.16.150 | 3306 | ONLINE | 5      | 0           | 1000            | 0                   | 0       | 0              |         |

| 20           | 192.168.140.52 | 3306 | ONLINE | 1      | 0           | 1000            | 0                   | 0       | 0              |         |

+--------------+----------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+

3 rows in set (0.00 sec)


您可能感兴趣的文档:

--结束END--

本文标题: proxysql配置读写分离策略和权重调整一例

本文链接: https://www.lsjlt.com/news/45062.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • sql怎么查看表的索引
    通过查询系统表,可以获取表的索引信息,包括索引名称、是否唯一、索引类型、索引列和行数。常用系统表有:mysql 的 information_schema.statistics、postg...
    99+
    2024-05-14
    mysql oracle
  • sql怎么查看索引
    您可以使用 sql 通过以下方法查看索引:show indexes 语句:显示表中定义的索引列表及其信息。explain 语句:显示查询计划,其中包含用于执行查询的索引。informat...
    99+
    2024-05-14
  • sql怎么查看存储过程
    如何查看 sql 存储过程的源代码:使用 show create procedure 语句直接获取创建脚本。查询 information_schema.routines 表的 routi...
    99+
    2024-05-14
  • sql怎么查看视图表
    要查看视图表,可以使用以下步骤:使用 select 语句获取视图中的数据。使用 desc 语句查看视图的架构。使用 explain 语句分析视图的执行计划。使用 dbms 提供...
    99+
    2024-05-14
    oracle python
  • sql怎么查看创建的视图
    可以通过sql查询查看已创建的视图,具体步骤包括:连接到数据库并执行查询select * from information_schema.views;查询结果将显示视图的名称、...
    99+
    2024-05-14
    mysql
  • sql怎么用循环语句实现查询
    可以通过 do 和 while 语句创建循环,并在循环内执行查询,详细步骤包括:定义循环变量设置循环初始值循环执行查询更新循环变量执行查询循环退出条件 SQL 中使用循环语句实现查询 ...
    99+
    2024-05-14
  • sql怎么用代码修改表中数据
    通过 sql 代码修改表中数据的方法包括:修改单个记录:使用 update 语句设置列值并指定条件。修改多条记录:在 update 语句中指定多个条件来修改满足条件的所有记录。增加新列:...
    99+
    2024-05-14
  • sql怎么用命令创建数据库
    在 sql 中使用 create database 命令创建新数据库,其语法包含以下步骤:指定数据库名称。指定数据库文件和日志文件的位置(可选)。指定数据库大小、最大大小和文件增长(可选...
    99+
    2024-05-14
  • sql怎么用身份证提取年龄
    sql 中提取身份证号码中的年龄的方法:提取出生日期部分(身份证号码中第 7-14 位);使用 to_date 函数转换为日期格式;使用 extract 函数计算与当前日期之间的年差。 ...
    99+
    2024-05-14
  • sql怎么看字段长度
    有两种方法可查看 sql 中的字段长度:使用 information_schema 架构,其中包含元数据信息,可用于查询字段长度。使用内建函数,如 length(),其适用于字符串数据类...
    99+
    2024-05-14
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作