ProxySQL 简介

ProxySQL是一个高性能的MySQL中间件,是灵活强大的MySQL代理层。像C罗一样的强大,可以实现读写分离,支持Query路由功能,支持动态指定某个SQL进行cache,支持动态加载配置、故障切换和一些SQL的过滤功能。现在由percona支持。

特性

连接池

主机和用户的最大连接数限制

自动下线后端DB

强大的规则路由引擎

支持prepared statement

支持Query Cache

支持负载均衡

ProxySQL 安装

相关网站

http://www.proxysql.com/ (官网)

https://www.percona.com/live/e17/sessions/utilizing-proxysql-for-connection-pooling-in-php

https://github.com/sysown/proxysql(git地址)

https://github.com/sysown/proxysql/wiki (帮助手册)

Ubuntu包安装

wget https://github.com/sysown/proxysql/releases/download/v1.4.9/proxysql_1.4.9-ubuntu16_amd64.deb

dpkg -i proxysql_1.4.9-ubuntu16_amd64.deb

查看服务是否安装成功

root@bd-All-Series:/var/run# proxysql -h

High Performance Advanced Proxy for MySQL

USAGE: proxysql [OPTIONS]

OPTIONS:

-c, --config ARG Configuraton file

-D, --datadir ARG Datadir

-e, --exit-on-error Do not restart ProxySQL if crashes

-f, --foreground Run in foreground

-h, -help, --help, --usage Display usage instructions.

-M, --no-monitor Do not start Monitor Module

-n, --no-start Starts only the admin service

-r, --reuseport Use SO_REUSEPORT

-S, --admin-socket ARG Administration Unix Socket

-V, --version Print version

--idle-threads Create auxiliary threads to handle idle connections

--initial Rename/empty database file

--reload Merge config file into database file

--sqlite3-server Enable SQLite3 Server

ProxySQL rev. 1.4.9-3-gd9fd599 -- Wed May 30 11:59:03 2018

Copyright (C) 2013-2017 René Cannaò

This program is free and without warranty

配置文件路径

/etc/proxysql.cnf

启动和停止命令

service proxysql start #systemctl start proxysql

service proxysql stop #systemctl stop proxysql

连接后台

root@bd-All-Series:/var/run# mysql -u admin -padmin -h 127.0.0.1 -P6032 --prompt='Admin> '

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 165106

Server version: 5.5.30 (ProxySQL Admin Module)

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.

Admin>

与mysql相勾结

修改配置文件

datadir="/var/lib/proxysql"

admin_variables=

{

admin_credentials="admin:admin"

mysql_ifaces="0.0.0.0:6032"

}

mysql_variables=

{

threads=4

max_connections=2048

default_query_delay=0

default_query_timeout=36000000

have_compress=true

poll_timeout=2000

interfaces="/var/run/proxysql.sock"

default_schema="information_schema"

stacksize=1048576

server_version="5.5.30"

connect_timeout_server=3000

monitor_username="monitor"

monitor_password="monitor"

monitor_history=600000

monitor_connect_interval=60000

monitor_ping_interval=10000

monitor_read_only_interval=1500

monitor_read_only_timeout=500

ping_interval_server_msec=120000

ping_timeout_server=500

commands_stats=true

sessions_sort=true

connect_retries_on_failure=10

}

mysql_servers =

(

{ address="127.0.0.1" , port=3306 , hostgroup=0 }

)

mysql_users:

(

{ username = "root" , password = "root" , default_hostgroup = 0 , active = 1 }

)

mysql_query_rules:

(

)

scheduler=

(

)

mysql_replication_hostgroups=

(

)

在MySQL中增加proxysql的监听用户,注意是在MySQL中添加

use mysql;

CREATE USER 'monitor'@'host' IDENTIFIED BY 'monitor';

grant all privileges on mq.* to monitor@localhost identified by 'monitor';

flush privileges;

重启proxysql服务

当我们修改了配置文件需要重新加载配置文件(存放在sqlite)

service proxysql initial

#其他相关命令

proxysql --initial #Rename/empty database file

proxysql --reload #Merge config file into database file

查看是否成功启动

root@bd-All-Series:/home/bd/soft# ps -ef |grep -v 'grep' | grep proxy

root 29165 1 0 16:20 ? 00:00:00 proxysql --initial -c /etc/proxysql.cnf -D /var/lib/proxysql

root 29166 29165 0 16:20 ? 00:00:24 proxysql --initial -c /etc/proxysql.cnf -D /var/lib/proxysql

代码测试

编写测试例子

//这里采用Unix Domain Socket形式连接proxysql,对应proxysql的配置文件

$host = '127.0.0.1';

$user = 'root';

$password = 'root';

$database = 'yiiadmin';

$charset = 'utf8';

$socket = '/var/run/proxysql.sock';

$dsn = "mysql:dbname={$database};charset={$charset}";

if (empty($_GET['proxysql'])) {

$dsn .= ";host={$host}";

} else {

$dsn .= ';unix_socket=/var/run/proxysql.sock';

}

echo $dsn .'
';

$dbh = new PDO($dsn, $user, $password);

$sql = 'SELECT * FROM admin LIMIT 10';

$value = $dbh->query($sql);

foreach ($value as $v) {

var_dump($v);

}

?>

ab测试

查看proxysql对MySQL的监控日志(在proxysql中查看)

Admin> SELECT * FROM monitor.mysql_server_ping_log limit 10;

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

| hostname | port | time_start_us | ping_success_time_us | ping_error |

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

| 127.0.0.1 | 3306 | 1531477104768035 | 233 | NULL |

| 127.0.0.1 | 3306 | 1531477114768168 | 231 | NULL |

| 127.0.0.1 | 3306 | 1531477124768243 | 235 | NULL |

| 127.0.0.1 | 3306 | 1531477134768373 | 217 | NULL |

| 127.0.0.1 | 3306 | 1531477144768454 | 241 | NULL |

| 127.0.0.1 | 3306 | 1531477154768586 | 234 | NULL |

| 127.0.0.1 | 3306 | 1531477164768663 | 235 | NULL |

| 127.0.0.1 | 3306 | 1531477174768792 | 235 | NULL |

| 127.0.0.1 | 3306 | 1531477184768866 | 240 | NULL |

| 127.0.0.1 | 3306 | 1531477194768994 | 214 | NULL |

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

10 rows in set (0.00 sec)

php mysql 代理_让PHP像C罗一样操作MySQL之ProxySQL相关推荐

  1. python mysql工具类_Python工具类(一)—— 操作Mysql数据库

    如何调用直接看__main__函数里如何调用此工具类就阔以啦! # encoding=utf-8 import pymysql # 导入所有Mysql配置常量,请自行指定文件 from conf.se ...

  2. 东财mysql作业_学习平台-15秋东财《MySQL数据库系统及应用》在线作业二(随机)-成人高等教育_成人本科教育报名_远程网络教育学院-江苏学历网报名服务中心...

    一.单选题(共15道试题,共60分.)V1.在mysql中一个新用户默认就有查看的权限 A.正确 B.错误 满分:4分 2.下列哪个命令用来修改用户名 A.setusername B.nameuser ...

  3. sonarqube下安装mysql数据库_本地安装SonarQube之一——win7环境安装mysql

    解压数据库(路径不要有t字开头的文件夹),然后配置环境变量,地址是${mysql5.7.20}/bin. 然后在${mysql5.7.20}文件夹下创建my.ini文件.文件内容如下: [mysql] ...

  4. sqoop同步hdfs与mysql端口_使用Sqoop将数据在HDFS与MySQL互导

    1.去官网下载sqoop,直接百度即可 2.解压后进入conf目录 guo@drguo1:/opt/sqoop-1.4.6.bin__hadoop-2.0.4-alpha/conf$ cp sqoop ...

  5. l源码安装mysql升级_[Linux]javaEE篇:源码安装mysql

    javaEE :源码安装mysql 安装环境 系统平台:CentOS-7-x86_64 数据库版本:mysql-5.6.14 源码安装mysql步骤: 一.卸载mysql 安装mysql之前,先确保l ...

  6. sql入侵 mysql日志_服务器入侵日志分析(一)——mysql日志位置确定

    安全应急响应工作中,一项重要任务就是要对mysql数据库的日志进行分析.我们通过对mysql日志记录的审计,发现攻击行为,进而追溯攻击源.在工作中遇见的各种服务器上,由于mysql安装方式不同,其日志 ...

  7. python进阶与数据操控_零基础机器学习Python进阶:Python操作MySql

    阅读文本大概需要 6 分钟 前言 基础写了十篇,以后会继续更,这是第二篇进阶,文末会放上链接,进阶分成另一个系列,柠檬有时间会整理好菜单栏让大家更方便的阅读基础和进阶,柠檬会把自己在当时做的项目写到进 ...

  8. phpnow mysql字符集_使用PHPnow搭建本地PHP环境+创建MySQL数据库

    要想学习WordPress建站,在本地搭建PHP环境是十分必要的,在以后的建站日子里,你可以使用这个环境来进行wordpress的程序学习.调试等工作,等你熟悉了wordpress以后,再购买域名和空 ...

  9. C MySql封装类 高性能连接池_在vc中通过连接池操作mysql(api方式),附c++访问mysql的封装类...

    在有大量节点访问的数据库设计中,经常要使用到连接池来管理所有的连接. 一般方法是:建立两个连接句柄队列,空闲的等待使用的队列和正在使用的队列. 当要查询时先从空闲队列中获取一个句柄,插入到正在使用的队 ...

最新文章

  1. VMware CTO:未来VMware NSX与思科ACI将有更多整合
  2. oracle xdb插件报错,注册XML Schema到ORACLE XDB并对XML进行验证
  3. Java TCP/UDP编程
  4. Layer 2 DAO 基础协议 Metis 上线 Alpha 测试网
  5. php mian函数,电脑main什么意思
  6. BZOJ3674: 可持久化并查集加强版
  7. 虚拟化查看服务器sn,查看服务器操作系统序列号
  8. OLED屏显和汉字点阵编码原理
  9. uc android flash插件,UC7.3 Android手机上网新体验 支持Flash游戏
  10. 为什么要购买域名?如何购买域名?
  11. win7 去除快捷方式小箭头
  12. Android后台Kill(二):ActivityManagerService与App现场恢复机制
  13. scipy中的imread,imresize怎么用
  14. 深入研究 CSSfloat属性
  15. ubuntu data backup and recovery
  16. android 一个应用两个入口一个应用两个快捷方式(不同图标显示)
  17. docker部署nginx 并实现反向代理 配置多个域名多个端口
  18. MySQL的SQL语句转PostgreSQL的SQL语句工具编写总结
  19. 2021年安全员-B证(山东省)考试APP及安全员-B证(山东省)作业考试题库
  20. 定时关闭电脑——《超级处理器》应用

热门文章

  1. 人工智能产业链深度透析-技术层
  2. LeetCode Python实现 二叉树简单部分
  3. js做的flash形式的幻灯图片
  4. 猎户星空否认停发高管薪资:无论遭遇怎样困难 都不会苛扣员工薪酬
  5. 恶意造谣水滴筹的违法分子已被警方依法处理
  6. 谷歌Pixel 6系列手机发布会官宣定档 10月19日发布
  7. 开放外链后,阿里旗下多个App已接入微信支付:更方便了
  8. 2021年Q2小米手机销量超苹果跻身全球第二 雷军:新的里程碑
  9. 难了!华为转身开始大卖4G手机
  10. 滴滴披露女司机数据:80后女性过半 24%全年零违章