Mysql read-Write separation-mysql router

Source: Internet
Author: User

Principle: MySQL router reads and writes according to the port, sends all requests that connect the read-write port to master, and all requests to the read-only port are polled to multiple slave for read-write separation

Master: Sql-master 192.168.200.101/24

From: Sql-slave 192.168.200.102/24,192.168.200.103/24

Mysql-router 192.168.200.104/24

Installing Mysql-router with RPM

RPM-IVH https://dev.mysql.com/get/Downloads/MySQL-Router/mysql-router-2.1.4-1.el7.x86_64.rpm

Vim/etc/mysqlrouter/mysqlrouter.conf

[DEFAULT]

Logging_folder =/var/log/mysqlrouter/

Plugin_folder =/usr/lib64/mysqlrouter

Runtime_folder =/var/run/mysqlrouter

Config_folder =/etc/mysqlrouter

[Logger]

Level = info

[KeepAlive]

Interval = 60

[Routing:read_write]

bind_address=192.168.200.104 #监听地址

bind_port=7001 #监听端口

destinations=192.168.200.101:3306 #mysql列表

Mode=read-write #指定读写

max_connections=1024

max_connect_errors=100

Client_connect_timeout=9

[Routing:read_only]

bind_address=192.168.200.104

bind_port=7002

destinations=192.168.200.102:3306,192.168.200.103:3306

Mode=read-only #指定只读

max_connections=65535

max_connect_errors=100

Client_connect_timeout=9

Systemctl Start Mysqlrouter

Systemctl Enable Mysqlrouter

Ss-ntlu

TCP LISTEN 0 192.168.200.106:7001 *:*

TCP LISTEN 0 192.168.200.106:7002 *:*

Primary Database configuration:

Mysql-u root-p123456

Create user test settings password 123456

MariaDB [(None)]> grant all on * * to [e-mail protected] ' 127.0.0.1 ' identified by "Hello";

MariaDB [(none)]> use MySQL;

Modify Host Permissions

MariaDB [(None)]> Update user Set host = '% ' where user = ' test ';

MariaDB [mysql]> Select User, host from user;

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

| user | Host |

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

| Test | %             |

Refreshing the database

MariaDB [mysql]> flush Privileges;

mysql-utest-p123456-h192.168.200.104-p7001

Mysql read-Write separation-mysql router

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.