MySQL读写分离(ProxySQL)

MySQL读写分离(ProxySQL)

读写分离原理

读写分离就是用户在发送请求时,请求经过中间件,中间件将请求中的读和写操作分辨出来将读请求发送给后端的从服务器,将写请求发送给后端的主服务器,再又主服务器通过主从复制将数据复制给其他从服务器

常见MySQL中间件

名称 公司 站点地址
mysql-proxy Oracle https://downloads.mysql.com/archives/proxy
Atlas Qihoo https://github.com/Qihoo360/Atlas/blob/master/README_ZH.md
dbproxy 美团 https://github.com/Meituan-Dianping/DBProxy
Cetus 网易乐得 https://github.com/Lede-Inc/cetus
Amoeba https://sourceforge.net/projects/amoeba/
Cobar 阿里巴巴 Amoeba的升级版
Mycat 基于Cobar http://www.mycat.io
ProxySQL https://proxysql.com/

本文以ProxySQL为例来介绍读写分离的使用方法

ProxySQL简介

ProxySQL为MySQL的中间件,其有两个版本官方版和percona版,percona版是基于官方版基础上修改而来。ProxySQL是由C++语言开发,轻量级但性能优异(支持处理千亿级数据),其具有中间件所需要的绝大多数功能,如:

  1. 多种方式的读写分离
  2. 定制基于用户、基于schema、基于语言的规则对SQL语句进行路由
  3. 缓存查询结果
  4. 后端节点的控制
    ...
    官方站点:https://proxysql.com/
    官方手册:https://github.com/sysown/proxysql/wiki

ProxySQL安装后生成的文件

/etc/init.d/proxysql            #此为服务脚本存放在init.d目录下所以需要使用service命令去启动他
/etc/proxysql.cnf
/usr/bin/proxysql
/usr/share/proxysql/tools/proxysql_galera_checker.sh
/usr/share/proxysql/tools/proxysql_galera_writer.pl

ProxySQL所使用的端口

ProxySQL所使用的端口为6032和6033
6032:用来配置ProxySQL,是个管理接口
6033:用来被远程用户连接端口

ProxySQL内置数据库

MySQL [(none)]> SHOW DATABASES;
+-----+---------------+-------------------------------------+
| seq | name          | file                                |
+-----+---------------+-------------------------------------+
| 0   | main          |                                     |
| 2   | disk          | /var/lib/proxysql/proxysql.db       |
| 3   | stats         |                                     |
| 4   | monitor       |                                     |
| 5   | stats_history | /var/lib/proxysql/proxysql_stats.db |
+-----+---------------+-------------------------------------+
5 rows in set (0.00 sec)

以上这些库中主要配置的库为main库,里面存放了ProxySQL的各种配置。

ProxySQL main库内的表

MySQL [(none)]> show tables;
+--------------------------------------------+
| tables                                     |
+--------------------------------------------+
| global_variables                           |
| mysql_collations                           |
| mysql_group_replication_hostgroups         |
| mysql_query_rules                          |
| mysql_query_rules_fast_routing             |
| mysql_replication_hostgroups               |
| mysql_servers                              |
| mysql_users                                |
| proxysql_servers                           |
| runtime_checksums_values                   |
| runtime_global_variables                   |
| runtime_mysql_group_replication_hostgroups |
| runtime_mysql_query_rules                  |
| runtime_mysql_query_rules_fast_routing     |
| runtime_mysql_replication_hostgroups       |
| runtime_mysql_servers                      |
| runtime_mysql_users                        |
| runtime_proxysql_servers                   |
| runtime_scheduler                          |
| scheduler                                  |
+--------------------------------------------+
20 rows in set (0.00 sec)

main库中的表分为runtime开头和非runtime开头
runtime开头为运行时的设置
非runtime开头为需要设置的配置
所有的配置修改后需要执行命令才能加载到runtime生效

LOAD ... TO RUNTIME

所有的配置修改后需要执行命令才能永久保存

SAVE ... TO DISK

日志查看

查看read_only和replication_log的监控日志

MySQL [(none)]> select * from mysql_server_read_only_log;
Empty set (0.00 sec)

MySQL [(none)]> select * from mysql_server_replication_lag_log;
Empty set (0.00 sec)

ProxySQL实现读写分离

ProxySQL在实现读写分离之前先要实现主从复制的共功能
本实验总计使用4台主机,详细配置如下

主机 ip地址
Client 192.168.73.113
ProxySQL 192.168.73.112
Master 192.168.73.110
Slave 192.168.73.111

注意事项:在实现主从复制时从节点在配置文件中必须要设置read_only,这是ProxySQL区分是用来作为读服务器还是写服务器的依据


一、实现主从复制

主节点配置

1.修改配置文件

[[email protected] ~]# vim /etc/my.cnf
[mysqld]
server-id=1
log-bin
binlog-format=row

2.启动MySQL服务

[[email protected] ~]# systemctl start mariadb
[[email protected] ~]# mysql -e "SHOW MASTER LOGS;"
+--------------------+-----------+
| Log_name           | File_size |
+--------------------+-----------+
| mariadb-bin.000001 |       245 |
+--------------------+-----------+

3.创建用来复制的账号

[[email protected] ~]# mysql -e "GRANT REPLICATION SLAVE ON *.* TO ‘repluser‘@‘192.168.73.%‘ IDENTIFIED BY ‘centos‘;"

从节点配置

1.修改配置文件

[[email protected] ~]# vim /etc/my.cnf
[mysqld]
server-id=2
log-bin
binlog-format=row
read-only               #必须写

2.启动数据库服务

[[email protected] ~]# systemctl start mariadb

3.写入CHANGE MASTSER TO信息

MariaDB [(none)]> CHANGE MASTER TO MASTER_HOST=‘192.168.73.110‘, MASTER_USER=‘repluser‘,MASTER_PASSWORD=‘centos‘,MASTER_PORT=3306,MASTER_LOG_FILE=‘mariadb-bin.000001‘,MASTER_LOG_POS=245;
Query OK, 0 rows affected (0.00 sec)

4.启动复制线程

MariaDB [(none)]> START SLAVE;
Query OK, 0 rows affected (0.00 sec)

5.查看状态

MariaDB [(none)]> SHOW SLAVE STATUS\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.73.110
                  Master_User: repluser
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mariadb-bin.000001
          Read_Master_Log_Pos: 402
               Relay_Log_File: mariadb-relay-bin.000002
                Relay_Log_Pos: 688
        Relay_Master_Log_File: mariadb-bin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes

测试

1.主节点导入数据库

[[email protected] ~]# mysql < hellodb_innodb.sql
[[email protected] ~]# mysql -e "SHOW DATABASES;"
+--------------------+
| Database           |
+--------------------+
| information_schema |
| hellodb            |
| mysql              |
| performance_schema |
| test               |
+--------------------+

2.从节点查看

[[email protected] ~]# mysql -e "SHOW DATABASES;"
+--------------------+
| Database           |
+--------------------+
| information_schema |
| hellodb            |
| mysql              |
| performance_schema |
| test               |
+--------------------+

主从复制配置完毕

二、在ProxySQL上配置读写分离

1.在ProxySQL主机上配置yum源

[[email protected] ~]# vim /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 

2.安装ProxySQL和mariadb客户端
ProxySQL内置了一个轻量级的数据库,所以需要有MySQL客户端连上去对其进行配置

[[email protected] ~]# yum install proxysql mariadb -y

3.启动ProxySQL服务

[[email protected] ~]# service proxysql start
Starting ProxySQL: 2019-05-08 14:03:07 [INFO] Using config file /etc/proxysql.cnf
DONE!

4.连接管理端口

[[email protected] ~]# mysql -uadmin -padmin -P6032 -h127.0.0.1
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.30 (ProxySQL Admin Module)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

5.将MySQL主从服务器信息添加入mysql_servers表中
先将主从服务器存放在同一组内,等指定好读写规则后,系统会根据配置文件中的read-only值自动将其分别添加至读组和写组。

MySQL [(none)]> INSERT INTO mysql_servers(hostgroup_id,hostname,port) VALUES (10,‘192.168.73.110‘,3306);
Query OK, 1 row affected (0.00 sec)

MySQL [(none)]> INSERT INTO mysql_servers(hostgroup_id,hostname,port) VALUES (10,‘192.168.73.111‘,3306);
Query OK, 1 row affected (0.00 sec)

MySQL [(none)]> 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.73.110 | 3306 | ONLINE | 1      | 0           | 1000            | 0                   | 0       | 0              |         |
| 10           | 192.168.73.111 | 3306 | ONLINE | 1      | 0           | 1000            | 0                   | 0       | 0              |         |
+--------------+----------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
2 rows in set (0.00 sec)

6.在MySQL服务器的主节点上为ProxySQL添加账号用来查看MySQL节点是主还是从

[[email protected] ~]# mysql -e "GRANT REPLICATION SLAVE ON *.* TO ‘monitor‘@‘192.168.73.%‘ IDENTIFIED BY ‘centos‘;"

7.在Proxy上配置监控账号

MySQL [(none)]> SET mysql-monitor_username=‘monitor‘;
Query OK, 1 row affected (0.00 sec)

MySQL [(none)]> SET mysql-monitor_password=‘centos‘;
Query OK, 1 row affected (0.00 sec)

8.将配置加载至内存,将配置保存至磁盘

MySQL [(none)]> LOAD MYSQL VARIABLES TO RUNTIME;
Query OK, 0 rows affected (0.00 sec)

MySQL [(none)]> SAVE MYSQL VARIABLES TO DISK;
Query OK, 97 rows affected (0.00 sec)

9.测试
9.1查看连接状态

MySQL [(none)]> select * from mysql_server_connect_log;
+----------------+------+------------------+-------------------------+-------------------------------------------------------------------------+
| hostname       | port | time_start_us    | connect_success_time_us | connect_error                                                           |
+----------------+------+------------------+-------------------------+-------------------------------------------------------------------------+
| 192.168.73.110 | 3306 | 1557296528658352 | 0                       | Access denied for user ‘monitor‘@‘192.168.73.112‘ (using password: YES) |
| 192.168.73.111 | 3306 | 1557296648056186 | 0                       | Access denied for user ‘monitor‘@‘192.168.73.112‘ (using password: YES) |
| 192.168.73.110 | 3306 | 1557296649025169 | 0                       | Access denied for user ‘monitor‘@‘192.168.73.112‘ (using password: YES) |
| 192.168.73.110 | 3306 | 1557296708057600 | 0                       | Access denied for user ‘monitor‘@‘192.168.73.112‘ (using password: YES) |
| 192.168.73.111 | 3306 | 1557296708872496 | 0                       | Access denied for user ‘monitor‘@‘192.168.73.112‘ (using password: YES) |
| 192.168.73.110 | 3306 | 1557296758752550 | 2763                    | NULL                                                                    |  #此前由于没有创建监控账号所以连接一直失败
| 192.168.73.111 | 3306 | 1557296759862679 | 3205                    | NULL                                                                    |
| 192.168.73.110 | 3306 | 1557296818752346 | 1014                    | NULL                                                                    |
| 192.168.73.111 | 3306 | 1557296819498108 | 3120                    | NULL                                                                    |
| 192.168.73.110 | 3306 | 1557296878752978 | 3245                    | NULL                                                                    |
| 192.168.73.111 | 3306 | 1557296879410404 | 3063                    | NULL                                                                    |
+----------------+------+------------------+-------------------------+-------------------------------------------------------------------------+
22 rows in set (0.00 sec)           

9.2测试连接ping

MySQL [(none)]> select * from mysql_server_ping_log;
+----------------+------+------------------+----------------------+-------------------------------------------------------------------------+
| hostname       | port | time_start_us    | ping_success_time_us | ping_error                                                              |
+----------------+------+------------------+----------------------+-------------------------------------------------------------------------+
| 192.168.73.111 | 3306 | 1557296508118738 | 0                    | Access denied for user ‘monitor‘@‘192.168.73.112‘ (using password: YES) |
| 192.168.73.110 | 3306 | 1557296508302837 | 0                    | Access denied for user ‘monitor‘@‘192.168.73.112‘ (using password: YES) |

...中间省略...

| 192.168.73.110 | 3306 | 1557297088874658 | 675                  | NULL                                                                    |
| 192.168.73.111 | 3306 | 1557297089037256 | 435                  | NULL                                                                    |
| 192.168.73.110 | 3306 | 1557297098875954 | 1144                 | NULL                                                                    |
| 192.168.73.111 | 3306 | 1557297099069333 | 1252                 | NULL                                                                    |
+----------------+------+------------------+----------------------+-------------------------------------------------------------------------+
122 rows in set (0.00 sec)
#已经可以联通

10.设置读写分组

MySQL [(none)]> INSERT INTO mysql_replication_hostgroups VALUES(10,20,"test");
Query OK, 1 row affected (0.00 sec)

MySQL [(none)]> SELECT * FROM mysql_replication_hostgroups;
+------------------+------------------+---------+
| writer_hostgroup | reader_hostgroup | comment |
+------------------+------------------+---------+
| 10               | 20               | test    |
+------------------+------------------+---------+
1 row in set (0.00 sec)

11.让读写表生效

MySQL [(none)]> LOAD MYSQL SERVERS TO RUNTIME;
Query OK, 0 rows affected (0.00 sec)

12.查看mysql_server表此时已经将服务器分组

MySQL [(none)]> 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.73.110 | 3306 | ONLINE | 1      | 0           | 1000            | 0                   | 0       | 0              |         |
| 20           | 192.168.73.111 | 3306 | ONLINE | 1      | 0           | 1000            | 0                   | 0       | 0              |         |
+--------------+----------------+------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
2 rows in set (0.00 sec)

13.保存配置至磁盘

MySQL [(none)]> SAVE MYSQL SERVERS TO DISK;
Query OK, 0 rows affected (0.02 sec)

至此读写分离配置完毕,接下来需要定义读写分离的规则

三、定义读写分离规则

1.在主节点上创建一个账户让客户端连接调度器去访问主从服务器(此处授予的权限较大,实际生产中可以根据需要定义指定的那张表)

[[email protected] ~]# mysql -e "GRANT ALL ON *.* TO ‘sqluser‘@‘192.168.73.%‘ IDENTIFIED BY ‘centos‘;"

2.在ProxySQL服务器上,将sqluser用户添加至mysql_users表中

MySQL [(none)]> INSERT INTO mysql_users(username,password,default_hostgroup) VALUES (‘sqluser‘,‘centos‘,10);
Query OK, 1 row affected (0.00 sec)

3.查看mysql_user表信息

MySQL [(none)]> SELECT * FROM mysql_users;
+----------+----------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+
| username | password | active | use_ssl | default_hostgroup | default_schema | schema_locked | transaction_persistent | fast_forward | backend | frontend | max_connections |
+----------+----------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+
| sqluser  | centos   | 1      | 0       | 10                | NULL           | 0             | 1                      | 0            | 1       | 1        | 10000           |
+----------+----------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+
1 row in set (0.00 sec)

4.生效存盘

MySQL [(none)]> load mysql users to runtime;
Query OK, 0 rows affected (0.00 sec)

MySQL [(none)]> SAVE MYSQL USERS TO DISK;
Query OK, 0 rows affected (0.00 sec)

5.测试
目前尚未设置读写路由规则,所有的请求都是发往主节点

[[email protected] ~]# mysql -usqluser -pcentos -h192.168.73.112 -P6033 -e "SELECT @@server_id;"
+-------------+
| @@server_id |
+-------------+
|           1 |
+-------------+

6.在ProxySQL上定义调度规则

MySQL [(none)]> 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);
Query OK, 2 rows affected (0.00 sec)

7.查看定义规则

MySQL [(none)]>  SELECT * FROM mysql_query_rules\G;
*************************** 1. row ***************************
              rule_id: 1
               active: 1
             username: NULL
           schemaname: NULL
               flagIN: 0
          client_addr: NULL
           proxy_addr: NULL
           proxy_port: NULL
               digest: NULL
         match_digest: ^SELECT.*FOR UPDATE$
        match_pattern: NULL
 negate_match_pattern: 0
         re_modifiers: CASELESS
              flagOUT: NULL
      replace_pattern: NULL
destination_hostgroup: 10
            cache_ttl: NULL
            reconnect: NULL
              timeout: NULL
              retries: NULL
                delay: NULL
    next_query_flagIN: NULL
       mirror_flagOUT: NULL
     mirror_hostgroup: NULL
            error_msg: NULL
               OK_msg: NULL
          sticky_conn: NULL
            multiplex: NULL
                  log: NULL
                apply: 1
              comment: NULL
*************************** 2. row ***************************
              rule_id: 2
               active: 1
             username: NULL
           schemaname: NULL
               flagIN: 0
          client_addr: NULL
           proxy_addr: NULL
           proxy_port: NULL
               digest: NULL
         match_digest: ^SELECT
        match_pattern: NULL
 negate_match_pattern: 0
         re_modifiers: CASELESS
              flagOUT: NULL
      replace_pattern: NULL
destination_hostgroup: 20
            cache_ttl: NULL
            reconnect: NULL
              timeout: NULL
              retries: NULL
                delay: NULL
    next_query_flagIN: NULL
       mirror_flagOUT: NULL
     mirror_hostgroup: NULL
            error_msg: NULL
               OK_msg: NULL
          sticky_conn: NULL
            multiplex: NULL
                  log: NULL
                apply: 1
              comment: NULL
2 rows in set (0.00 sec)

8.生效存盘

MySQL [(none)]> LOAD MYSQL QUERY RULES TO RUNTIME;
Query OK, 0 rows affected (0.00 sec)

MySQL [(none)]> SAVE MYSQL QUERY RULES TO DISK;
Query OK, 0 rows affected (0.00 sec)

四、在Client端测试

1.查询操作

[[email protected] ~]# mysql -usqluser -pcentos -h192.168.73.112 -P6033 -e "SELECT @@server_id;"
+-------------+
| @@server_id |
+-------------+
|           2 |
+-------------+

2.写操作

[[email protected] ~]# mysql -usqluser -pcentos -h192.168.73.112 -P6033 -e "BEGIN;INSERT hellodb.teachers VALUE(5,‘Long‘,30,‘M‘);SELECT @@server_id;commit;"
+-------------+
| @@server_id |
+-------------+
|           1 |
+-------------+

原文地址:https://blog.51cto.com/11886307/2391101

时间: 2024-11-08 09:14:13

MySQL读写分离(ProxySQL)的相关文章

MySQL读写分离ProxySQL

环境: master —— 192.168.10.1slave ——— 192.168.10.2proxysql —— 192.168.10.3client ——— 192.168.10.4 master节点 1.安装mariadb 2.编辑配置文件 /etc/my.cnf,并添加如下内容 3.启动服务 4.登录MySQL,创建有复制权限的用户账号,查看二进制日志文件位置 slave节点 1.安装mariadb 2.编辑配置文件 /etc/my.cnf,并添加如下内容 3.启动服务4.登录MyS

专职DBA-基于MHA高可用搭建MySQL读写分离架构-Atlas

专职DBA-基于MHA高可用搭建MySQL读写分离架构-Atlas 1.Atlas介绍 Atlas是由Qihoo360,Web平台部基础架构团队开发维护的一个基于MySQL协议的数据中间层项目. 它是在mysql-proxy-0.8.2版本的基础上,对其进行了优化,增加了一些新的功能特性. 360内部使用Atlas运行的mysql业务,每天承载的读写请求数达几十亿条. 下载地址:https://github.com/Qihoo360/Atlas/releases 注意: 1.Atlas只能安装运

mysql读写分离的三种实现方式

1 程序修改mysql操作类可以参考PHP实现的Mysql读写分离,阿权开始的本项目,以php程序解决此需求.优点:直接和数据库通信,简单快捷的读写分离和随机的方式实现的负载均衡,权限独立分配缺点:自己维护更新,增减服务器在代码处理 2 amoeba参考官网:http://amoeba.meidusa.com/优点:直接实现读写分离和负载均衡,不用修改代码,有很灵活的数据解决方案缺点:自己分配账户,和后端数据库权限管理独立,权限处理不够灵活 3 mysql-proxy参考 mysql-proxy

mysql读写分离

mysql读写分离  静态分离:直接将服务器地址写入程序  动态分离:通过代理服务器对数据进行读写操作,由代理服务器判定读写操作,在主服务器上写数据,在          从服务器上读数据.    1.使用mysql-proxy实现读写分离  # ./mysql-proxy --proxy-backend-addresses=10.0.5.150:3306 --proxy-read-only-backend-addresses=10.0.5.151:3306 --proxy-lua-script

MySQL学习笔记之十:使用mysql-proxy实现MySQL读写分离

MySQL读写分离是指让master处理写操作,让slave处理读操作,非常适用于读操作量比较大的场景,可减轻master的压力. 本文使用mysql-proxy实现mysql的读写分离,mysql-proxy实际上是作为后端mysql主从服务器的代理,它直接接受客户端的请求,对SQL语句进行分析,判断出是读操作还是写操作,然后分发至对应的mysql服务器上.对于多节点slave集群,还可以起到负载均衡的效果. 一.准备实验环境 MySQL的主从复制架构搭建详见http://9124573.bl

Mysql-Proxy实现mysql读写分离、负载均衡 (转)

在mysql中实现读写分离.负载均衡,用Mysql-Proxy是很容易的事,不过大型处理对于性能方面还有待提高,主要配置步骤如下: 1.1. mysql-proxy安装 MySQL Proxy就是这么一个中间层代理,简单的说,MySQL Proxy就是一个连接池,负责将前台应用的连接请求转发给后台的数据库,并且通过使用lua脚本,可以实现复杂的连接控制和过滤,从而实现读写分离和负 载平衡.对于应用来说,MySQL Proxy是完全透明的,应用则只需要连接到MySQL Proxy的监听端口即可.当

django mysql 读写分离

最近需要用到Django的MySQL读写分离技术,查了一些资料,把方法整理了下来. 在Django里实现对MySQL的读写分离,实际上就是将不同的读写请求按一定的规则路由到不同的数据库上(可以是不同类型的数据库),我们需要做的就是,定义不同的数据库,定义不同的路由规则.当然前提是你需要手动实现MySQL的主从同步.. 首先定义我们的主从数据库: DATABASES = {     'default': {         'ENGINE': 'django.db.backends.mysql',

Amoeba实现Mysql读写分离

环境规划 Amoeba读写分离器 172.16.254.144/16 Mysql服务器(master) 172.16.254.150/16 Mysql服务器(slave) 172.16.254.151/16 一.先实现mysql主从复制,在master上使用yum安装mysql [[email protected] mysql]# yum -y install mysql mysql-server 启用二进制日志,编辑/etc/my.cnf在[mysqld]下添加如下行: log-bin = /

mysql读写分离 mysql-proxy

一.介绍 MySQL代理是一个介于MySQL客户端和MySQL服务器之间的简单程序,可用来监视.分析或者传输他们之间的通讯.他的灵活性允许你最大限度的使用它,这些包括负载平衡.容错 .分析查询和修正等等: MySQL Proxy就是这么一个中间层代理,简单的说,MySQL Proxy就是一个连接池,负责将前台应用的连接请求转发给后台的数据库,并且通过使用lua脚本,可以实现复杂的连接控制和过滤,从而实现读写分离和负载平衡.对于应用来说,MySQL Proxy是完全透明的,应用则只需要连接到MyS