在线精品99_中国九九盗摄偷拍偷看_91免费版在线观看_91.app_91高清视频在线_99热最新网站

如何使用proxysql 1.4.14中间件实现mysql 5.7.26主从的读写分离

124次阅读
没有评论

共计 5388 个字符,预计需要花费 14 分钟才能阅读完成。

这篇文章将为大家详细讲解有关如何使用 proxysql 1.4.14 中间件实现 mysql 5.7.26 主从的读写分离,丸趣 TV 小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

准备条件

操作系统  redhat 6.9

数据库      mysql 5.7.26

中间件      proxysql 1.4.14

已配置 mysql 一主一从,具体见下

数据库读写分离整体架构

编号     服务器角色    ip 地址             端口

1         proxysql        10.0.0.13         6032,6033(注:6032 是 proxysql 的管理端口,6033 是 proxysql 对外服务的端口)

2         mysql 主库     10.0.0.11         3306

3         mysql 从库     10.0.0.12         3306

配置数据库读写分离

1, 登陆中间件 proxysql

[root@mysqlclient ~]# mysql -uadmin -padmin -h227.0.0.1 -P6032

2, 配置用于读写分离的不同的主机组,10 用于 mysql 主库的主机组,20 用于 mysql 从库的主机组

mysql insert into mysql_replication_hostgroups values(10,20, use for msyql primary replication

Query OK, 1 row affected (0.00 sec)

mysql select * from mysql_replication_hostgroups;

+——————+——————+———————————–+

| writer_hostgroup | reader_hostgroup | comment                           |

+——————+——————+———————————–+

| 10               | 20               | use for msyql primary replication |

+——————+——————+———————————–+

1 row in set (0.00 sec)

3, 登陆 mysql 主库创建用于监控 mysql 主从库 read_only 是否只读的数据库用户 monitor

mysql grant replication client on *.*  to monitor @ 10.0.0.13 identified by monitor

Query OK, 0 rows affected (0.02 sec)

4, 登陆 mysql 从库确认 read_only=on 只读

mysql show global variables like read_only

+—————+——-+

| Variable_name | Value |

+—————+——-+

| read_only     | ON    |

+—————+——-+

1 row in set (0.00 sec)

5, 登陆中间件 proxysql 配置用于监控 mysql 的数据库用户及密码

(注:对应上述第 3 步配置的数据库用户)

mysql select * from main.global_variables where variable_name in (mysql-monitor_username , mysql-monitor_password

+————————+—————-+

| variable_name          | variable_value |

+————————+—————-+

| mysql-monitor_password | monitor        |

| mysql-monitor_username | monitor        |

+————————+—————-+

2 rows in set (0.00 sec)

– 如果配置的数据库用户密码不对,根据实际情况进行调整

mysql set mysql-monitor_username= monitor

Query OK, 1 row affected (0.00 sec)

mysql set mysql-monitor_password= monitor

Query OK, 1 row affected (0.00 sec)

– 持久化

mysql load mysql variables to runtime;

Query OK, 0 rows affected (0.00 sec)

mysql save mysql variables to disk;

Query OK, 97 rows affected (0.02 sec)

6,配置 mysql 主从节点与主机组的对应关系

(注:不同的 mysql 节点对应不同的主机组,实现读写分离)

mysql insert into mysql_servers(hostgroup_id,hostname,port) values(10, 10.0.0.11 ,3306);

Query OK, 1 row affected (0.00 sec)

mysql insert into mysql_servers(hostgroup_id,hostname,port) values(20, 10.0.0.12 ,3306);

Query OK, 1 row affected (0.00 sec)

持久化

mysql load mysql servers to runtime;

Query OK, 0 rows affected (0.01 sec)

mysql save mysql servers to disk;

Query OK, 0 rows affected (0.03 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           | 10.0.0.11 | 3306 | ONLINE | 1      | 0           | 1000            | 0                   | 0       | 0              |         |

| 20           | 10.0.0.12 | 3306 | ONLINE | 1      | 0           | 1000            | 0                   | 0       | 0              |         |

+————–+———–+——+——–+——–+————-+—————–+———————+———+—————-+———+

2 rows in set (0.00 sec)

7, 登陆 mysql 主库创建用于读写分离的数据库用户

– 读写数据库用户

mysql grant all on *.* to rwuser@ 10.0.0.11 identified by system

Query OK, 0 rows affected (0.02 sec)

– 只读数据库用户

mysql grant all on *.* to rouser@ 10.0.0.12 identified by system

Query OK, 0 rows affected (0.01 sec)

8, 登陆中间件 proxysql 配置数据库用户与主机组的对应关系,即不同的数据库用户可以导流到不同的 mysql 主从的节点上

mysql insert into mysql_users(username,password,default_hostgroup) values(rwuser , system ,10);

Query OK, 1 row affected (0.00 sec)

mysql insert into mysql_users(username,password,default_hostgroup) values(rouser , system ,20);

Query OK, 1 row affected (0.00 sec)

– 持久化

mysql load mysql users to runtime;

Query OK, 0 rows affected (0.00 sec)

mysql save mysql users to disk;

Query OK, 0 rows affected (0.02 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 |

+———-+———-+——–+———+——————-+—————-+—————+————————+————–+———+———-+—————–+

| rwuser   | system   | 1      | 0       | 10                | NULL           | 0             | 1                      | 0            | 1       | 1        | 10000           |

| rouser   | system   | 1      | 0       | 20                | NULL           | 0             | 1                      | 0            | 1       | 1        | 10000           |

+———-+———-+——–+———+——————-+—————-+—————+————————+————–+———+———-+—————–+

2 rows in set (0.00 sec)

9,客户端使用不同的数据库用户登陆中间件,实现 mysql 主从库的读写分离

(注:rwuser 数据库用户访问 mysql 主库,rouser 数据库用户访问 mysql 从库)

[root@mysqlclient proxydir]# mysql -urwuser -psystem -h227.0.0.1 -P6033 -e select @@server_id

Warning: Using a password on the command line interface can be insecure.

+————-+

| @@server_id |

+————-+

|           1 |

+————-+

[root@mysqlclient proxydir]# mysql -urouser -psystem -h227.0.0.1 -P6033 -e select @@server_id

Warning: Using a password on the command line interface can be insecure.

+————-+

| @@server_id |

+————-+

|           2 |

+————-+

[root@mysqlclient proxydir]# 

关于“如何使用 proxysql 1.4.14 中间件实现 mysql 5.7.26 主从的读写分离”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-27发表,共计5388字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)
主站蜘蛛池模板: 少妇无码一区二区三区免费 | 在线观看欧洲成人免费视频 | 色噜噜在线 | 亚洲第一页中文字幕 | 日韩电影免费在线观看中文字幕 | 久久中文字幕无码一区二区 | 国产主播在线看 | 777国产偷窥盗摄精品品在线 | 2020国产免费久久精品99 | 青青草精品视频 | 综合视频在线 | 一级特级aa欧美毛片 | 欧美日韩亚洲成人 | 91国内精品久久久久影院优播 | 图片区自拍区 | 狠狠亚洲丁香综合久久 | 午夜影院免费观看视频 | 少妇人妻偷人精品无码视频 | 免费看黄色大片 | 国内精品无码一区二区三区 | 中文字幕亚洲乱码熟女一区二区 | 久青草国产97香蕉在线视频 | 国产日产人妻精品精品 | 思思久久96热在精品不卡 | 日韩欧美综合 | 中国xxxxwwww | 四虎地址 | 天天躁夜夜躁天干天干2020 | 亚洲男人天堂 | 男女一边摸一边做爽爽的免费阅读 | 午夜影院404| www.拔插拔插| 久久久久久日本一区99 | 国产在线精品一区二区三区 | 国产日本免费 | 国产真实伦1 | 国产精品成人久久电影 | 亚洲精品二区国产综合野狼 | 免费毛毛片 | 内射毛片内射国产夫妻 | 国产成人精品在线观看 |