SlideShare a Scribd company logo
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 121
MySQL Proxy
A powerful, flexible MySQL toolbox
Miguel Araújo
Software Developer @
MySQL Enterprise Tools
3 April 2014
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.3
Agenda
1. What is MySQL Proxy?
2. Overview / Concepts
3. Architecture
1. Usage
2. Plugins
4. Scenarios
1. Examples / Demo!
5. How can we improve?
6. Q/A
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.4
What is MySQL Proxy?
Do you know it?
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.5
What is MySQL Proxy?
●
Stands between the client and the server
●
“Speaks” MySQL
●
Can analyze, block, inject, rewrite, route queries...
●
A good MitM!
Do you know it?
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.6
Overview / Concepts
 Transparent to the client
 Supports all major platforms
 GPLv2 license
 Plugins layer
 Customized with Lua scripts
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.7
Overview / Concepts
 Transparent to the client
 Supports all major platforms
 GPLv2 license
 Plugins layer
 Customized with Lua scripts
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.8
Overview / Concepts
Use-cases
 Query analysis
 Query manipulation
 Load balancing
 Fail over
 Sharding
 R/W splitting
 Pooling
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.9
Architecture
4 Layers
Chassis
La
scripting
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.10
Architecture
4 Layers
Chassis
Network Core
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.11
Architecture
4 Layers
Chassis
Network Core
Plugins
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.12
Architecture
4 Layers
Chassis
Network Core
Plugins
Lua
scripting
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.13
Architecture
Detail
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.14
 How do I start proxy?
 Which are the command-line options?
 Can I have a configuration file?
 How does it look like?
Architecture
Usage
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.15
Demo!
Architecture
Usage
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.16
Architecture
Plugins: Proxy plugin
 MySQL Proxy “is” actually, the Proxy plugin
 Accepts connections on its “--proxy-address”
 Forwards data to the “--proxy-backend-addresses”
 We can provide a Lua script with “--proxy-lua-script”
 Exposes hooks to the scripting layer:
➔
connect_server()
➔
read_query()
➔
read_query_result()
➔
...
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.17
Demo!
Architecture
Plugins: Proxy plugin
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.18
Architecture
Plugins: Admin plugin
 Administration interface
 Only authenticated users can use it
➔
--admin-username
➔
--admin-password
 Provides information about the proxy server
 We must use a Lua script...
➔
--admin-lua-script
 … to access the internal components of mysql-proxy
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.19
Demo!
Architecture
Plugins: Admin plugin
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.20
Scenarios
Query manipulation
Let's intercept some
user queries and
rewrite them...
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.21
Scenarios
Query manipulation
Let's intercept some
user queries and
rewrite them...
rewrite.lua
function read_query (packet)
if packet:byte() == proxy.COM_QUERY then
...
if string.match(string.upper(query),
'foo') then
proxy.queries:append(1,
string.char(proxy.COM_QUERY) .. "bar")
return proxy.PROXY_SEND_QUERY
end
end
end
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.22
Demo!
Scenarios
Query manipulation
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.23
Scenarios
Query injection
Let's inject some
useful SQL for certain
queries...
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.24
Scenarios
Query injection
Let's inject some
useful SQL for certain
queries...
inject.lua
function read_query (packet)
...
proxy.queries:append(2,
string.char(proxy.COM_QUERY) .. "SELECT
CURRENT_USER()", {resultset_is_needed = true})
...
end
function read_query_result(inj)
...
if (inj.id == 2) then
for row in inj.resultset.rows do
...
end
return proxy.PROXY_IGNORE_RESULT
end
end
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.25
Demo!
Scenarios
Query injection
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.26
Scenarios
Load balancing
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.27
Scenarios
Load balancing
ro-pooling.lua
function connect_server (packet)
--get a connection to a backend...
...
end
function read_auth_result (auth)
--successful connection? Put it on the pool
...
end
function read_query (packet)
--get the first idle server and choose it
for backend connection
...
end
function read_query_result (inj)
--manage backends use
end
function disconnect_client ()
--manage disconnected clients
end
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.28
Scenarios
R/W splitting
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.29
Scenarios
R/W splitting
rw-splitting.lua
function connect_server (packet)
--get a connection to a backend...
...
end
function read_auth_result (auth)
--successful connection? Put it on the pool
...
end
function read_query (packet)
--use the tokenizer to check if query is a
SELECT. If so pick an idle slave if not pick
the master
...
end
function read_query_result (inj)
--manage backends use
end
function disconnect_client ()
--manage disconnected clients
end
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.30
Demo!
Scenarios
R/W splitting
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.31

Used worldwide

Used in production
Scenarios
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.32
How can we improve?
Problems / Solutions
Performance issues due to global plugin lock
Plugins loaded at start
Scripting restricted to Lua
Admin plugin limited
Code can be optimized
0.8.4 Next... (0.9.0)
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.33
Any questions?
Download from: http://dev.mysql.com/downloads/mysql-proxy/
Code @ launchpad.net/mysql-proxy
mailto: miguel.araujo@oracle.com; jan.kneschke@oracle.com;
mark.leith@oracle.com
IRC: miguelaraujo / weigon / leithal in #mysql-proxy on irc.freenode.net
Thanks!

More Related Content

PDF
MySQL Shell - The DevOps Tool for MySQL
PDF
MySQL InnoDB Cluster / ReplicaSet - Making Provisioning & Troubleshooting as ...
PDF
Disaster Recovery with MySQL InnoDB ClusterSet - What is it and how do I use it?
PDF
MySQL Replication Performance in the Cloud
PDF
MySQL Shell - A DevOps-engineer day with MySQL’s development and administrati...
PDF
MySQL Shell - The Best MySQL DBA Tool
PDF
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
PDF
MySQL InnoDB Cluster: Management and Troubleshooting with MySQL Shell
MySQL Shell - The DevOps Tool for MySQL
MySQL InnoDB Cluster / ReplicaSet - Making Provisioning & Troubleshooting as ...
Disaster Recovery with MySQL InnoDB ClusterSet - What is it and how do I use it?
MySQL Replication Performance in the Cloud
MySQL Shell - A DevOps-engineer day with MySQL’s development and administrati...
MySQL Shell - The Best MySQL DBA Tool
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
MySQL InnoDB Cluster: Management and Troubleshooting with MySQL Shell

What's hot (20)

PDF
MySQL InnoDB Cluster / ReplicaSet - Tutorial
PDF
MySQL Group Replication - Ready For Production? (2018-04)
PDF
State of the Dolphin 2020 - 25th Anniversary of MySQL with 8.0.20
PDF
MySQL Database Architectures - InnoDB ReplicaSet & Cluster
PDF
preFOSDEM MySQL Day - Best Practices to Upgrade to MySQL 8.0
PDF
MySQL Connectors 8.0.19 & DNS SRV
PDF
MySQL InnoDB Cluster - New Features in 8.0 Releases - Best Practices
PDF
MySQL Database Architectures - 2020-10
PDF
MySQL User Camp: GTIDs
PDF
MySQL Shell: the best DBA tool !
PDF
MySQL InnoDB Cluster - Advanced Configuration & Operations
PDF
FOSDEM 2022 MySQL Devroom: MySQL 8.0 - Logical Backups, Snapshots and Point-...
PDF
MySQL Group Replication: Handling Network Glitches - Best Practices
PPTX
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
PDF
From single MySQL instance to High Availability: the journey to MySQL InnoDB ...
PDF
Java EE 7 for WebLogic 12c Developers
PDF
Oracle Open World Middle East - MySQL 8 a Giant Leap for SQL
PDF
Oracle OpenWorld 2013 - HOL9737 MySQL Replication Best Practices
PDF
Another MySQL HA Solution for ProxySQL Users, Easy and All Integrated: MySQL ...
PDF
MySQL Operator for Kubernetes
MySQL InnoDB Cluster / ReplicaSet - Tutorial
MySQL Group Replication - Ready For Production? (2018-04)
State of the Dolphin 2020 - 25th Anniversary of MySQL with 8.0.20
MySQL Database Architectures - InnoDB ReplicaSet & Cluster
preFOSDEM MySQL Day - Best Practices to Upgrade to MySQL 8.0
MySQL Connectors 8.0.19 & DNS SRV
MySQL InnoDB Cluster - New Features in 8.0 Releases - Best Practices
MySQL Database Architectures - 2020-10
MySQL User Camp: GTIDs
MySQL Shell: the best DBA tool !
MySQL InnoDB Cluster - Advanced Configuration & Operations
FOSDEM 2022 MySQL Devroom: MySQL 8.0 - Logical Backups, Snapshots and Point-...
MySQL Group Replication: Handling Network Glitches - Best Practices
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
From single MySQL instance to High Availability: the journey to MySQL InnoDB ...
Java EE 7 for WebLogic 12c Developers
Oracle Open World Middle East - MySQL 8 a Giant Leap for SQL
Oracle OpenWorld 2013 - HOL9737 MySQL Replication Best Practices
Another MySQL HA Solution for ProxySQL Users, Easy and All Integrated: MySQL ...
MySQL Operator for Kubernetes
Ad

Viewers also liked (20)

PDF
High Availability with MySQL
PDF
MySQL Proxy: Architecture and concepts of misuse
PPTX
MySQL Fabric: High Availability using Python/Connector
PDF
MySQL highav Availability
PDF
MySQL Proxy. From Architecture to Implementation
PPTX
ScaleBase Webinar: Scaling MySQL - Sharding Made Easy!
PDF
DIY: A distributed database cluster, or: MySQL Cluster
PDF
MySQL Proxy tutorial
PDF
MySQL HA Solutions
ODP
MySQL? Load? Clustering! Balancing! PECL/mysqlnd_ms 1.4
PDF
MySQL High Availability Deep Dive
ODP
MySQL 5.6 Global Transaction IDs - Use case: (session) consistency
PDF
MySQL High Availability and Disaster Recovery with Continuent, a VMware company
PDF
High-Availability using MySQL Fabric
PDF
MySQL Replication: What’s New in MySQL 5.7 and Beyond
PPTX
Using MySQL Fabric for High Availability and Scaling Out
PDF
ProxySQL - High Performance and HA Proxy for MySQL
PDF
Methods of Sharding MySQL
PDF
MySQL Day Paris 2016 - MySQL HA: InnoDB Cluster and NDB Cluster
PDF
Best practices for MySQL/MariaDB Server/Percona Server High Availability
High Availability with MySQL
MySQL Proxy: Architecture and concepts of misuse
MySQL Fabric: High Availability using Python/Connector
MySQL highav Availability
MySQL Proxy. From Architecture to Implementation
ScaleBase Webinar: Scaling MySQL - Sharding Made Easy!
DIY: A distributed database cluster, or: MySQL Cluster
MySQL Proxy tutorial
MySQL HA Solutions
MySQL? Load? Clustering! Balancing! PECL/mysqlnd_ms 1.4
MySQL High Availability Deep Dive
MySQL 5.6 Global Transaction IDs - Use case: (session) consistency
MySQL High Availability and Disaster Recovery with Continuent, a VMware company
High-Availability using MySQL Fabric
MySQL Replication: What’s New in MySQL 5.7 and Beyond
Using MySQL Fabric for High Availability and Scaling Out
ProxySQL - High Performance and HA Proxy for MySQL
Methods of Sharding MySQL
MySQL Day Paris 2016 - MySQL HA: InnoDB Cluster and NDB Cluster
Best practices for MySQL/MariaDB Server/Percona Server High Availability
Ad

Similar to MySQL Proxy. A powerful, flexible MySQL toolbox. (20)

ODP
Mysql Proxy Presentation Yahoo
ODP
Mysql proxy presentation_yahoo
PPTX
Proxysql use case scenarios plam 2016
PPTX
Proxysql use case scenarios fosdem17
PPTX
Proxysql use case scenarios hl++ 2017
PPTX
ProxySQL Use Case Scenarios / Alkin Tezuysal (Percona)
PDF
ProxySQL Tutorial - PLAM 2016
PDF
MySQL Proxy
PPTX
OUGLS 2016: Guided Tour On The MySQL Source Code
PDF
HandsOn ProxySQL Tutorial - PLSC18
ODP
HTTP, JSON, JavaScript, Map&Reduce built-in to MySQL
PDF
My Sql Proxy
PPT
Proxy Servers
ODP
PHP mysqlnd connection multiplexing plugin
PDF
MySQL Connector/Node.js and the X DevAPI
DOC
seminar on proxyserver
PDF
Using aphace-as-proxy-server
PDF
MySQL's NoSQL -- Texas Linuxfest August 22nd 2015
PDF
HTTP Plugin for MySQL!
Mysql Proxy Presentation Yahoo
Mysql proxy presentation_yahoo
Proxysql use case scenarios plam 2016
Proxysql use case scenarios fosdem17
Proxysql use case scenarios hl++ 2017
ProxySQL Use Case Scenarios / Alkin Tezuysal (Percona)
ProxySQL Tutorial - PLAM 2016
MySQL Proxy
OUGLS 2016: Guided Tour On The MySQL Source Code
HandsOn ProxySQL Tutorial - PLSC18
HTTP, JSON, JavaScript, Map&Reduce built-in to MySQL
My Sql Proxy
Proxy Servers
PHP mysqlnd connection multiplexing plugin
MySQL Connector/Node.js and the X DevAPI
seminar on proxyserver
Using aphace-as-proxy-server
MySQL's NoSQL -- Texas Linuxfest August 22nd 2015
HTTP Plugin for MySQL!

More from Miguel Araújo (13)

PDF
Routing Guidelines: Unlocking Smarter Query Routing in MySQL Architectures
PDF
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
PDF
MySQL Router - Explore The Secrets (MySQL Belgian Days 2024)
PDF
MySQL Shell/AdminAPI - MySQL Architectures Made Easy For All!
PDF
Deep Dive into MySQL InnoDB Cluster Read Scale-out Capabilities.pdf
PDF
MySQL Database Architectures - High Availability and Disaster Recovery Solution
PDF
MySQL InnoDB Cluster / ReplicaSet - Tutorial
PDF
MySQL Shell: The DevOps Tool for MySQL
PDF
MySQL 8 High Availability with InnoDB Clusters
PDF
FOSDEM'18: MySQL InnoDB Cluster - MySQL HA Made Easy!
PDF
SLQ vs NOSQL - friends or foes
PDF
Asynchronous Replication of Databases
PDF
Evaluating Data Freshness in Large Scale Replicated Databases
Routing Guidelines: Unlocking Smarter Query Routing in MySQL Architectures
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
MySQL Router - Explore The Secrets (MySQL Belgian Days 2024)
MySQL Shell/AdminAPI - MySQL Architectures Made Easy For All!
Deep Dive into MySQL InnoDB Cluster Read Scale-out Capabilities.pdf
MySQL Database Architectures - High Availability and Disaster Recovery Solution
MySQL InnoDB Cluster / ReplicaSet - Tutorial
MySQL Shell: The DevOps Tool for MySQL
MySQL 8 High Availability with InnoDB Clusters
FOSDEM'18: MySQL InnoDB Cluster - MySQL HA Made Easy!
SLQ vs NOSQL - friends or foes
Asynchronous Replication of Databases
Evaluating Data Freshness in Large Scale Replicated Databases

Recently uploaded (20)

PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
L1 - Introduction to python Backend.pptx
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
System and Network Administraation Chapter 3
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
top salesforce developer skills in 2025.pdf
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
ai tools demonstartion for schools and inter college
PPTX
Reimagine Home Health with the Power of Agentic AI​
Design an Analysis of Algorithms I-SECS-1021-03
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
L1 - Introduction to python Backend.pptx
Navsoft: AI-Powered Business Solutions & Custom Software Development
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
System and Network Administraation Chapter 3
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Internet Downloader Manager (IDM) Crack 6.42 Build 41
How to Migrate SBCGlobal Email to Yahoo Easily
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
top salesforce developer skills in 2025.pdf
Operating system designcfffgfgggggggvggggggggg
Softaken Excel to vCard Converter Software.pdf
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
ai tools demonstartion for schools and inter college
Reimagine Home Health with the Power of Agentic AI​

MySQL Proxy. A powerful, flexible MySQL toolbox.

  • 1. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 121
  • 2. MySQL Proxy A powerful, flexible MySQL toolbox Miguel Araújo Software Developer @ MySQL Enterprise Tools 3 April 2014
  • 3. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.3 Agenda 1. What is MySQL Proxy? 2. Overview / Concepts 3. Architecture 1. Usage 2. Plugins 4. Scenarios 1. Examples / Demo! 5. How can we improve? 6. Q/A
  • 4. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.4 What is MySQL Proxy? Do you know it?
  • 5. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.5 What is MySQL Proxy? ● Stands between the client and the server ● “Speaks” MySQL ● Can analyze, block, inject, rewrite, route queries... ● A good MitM! Do you know it?
  • 6. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.6 Overview / Concepts  Transparent to the client  Supports all major platforms  GPLv2 license  Plugins layer  Customized with Lua scripts
  • 7. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.7 Overview / Concepts  Transparent to the client  Supports all major platforms  GPLv2 license  Plugins layer  Customized with Lua scripts
  • 8. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.8 Overview / Concepts Use-cases  Query analysis  Query manipulation  Load balancing  Fail over  Sharding  R/W splitting  Pooling
  • 9. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.9 Architecture 4 Layers Chassis La scripting
  • 10. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.10 Architecture 4 Layers Chassis Network Core
  • 11. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.11 Architecture 4 Layers Chassis Network Core Plugins
  • 12. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.12 Architecture 4 Layers Chassis Network Core Plugins Lua scripting
  • 13. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.13 Architecture Detail
  • 14. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.14  How do I start proxy?  Which are the command-line options?  Can I have a configuration file?  How does it look like? Architecture Usage
  • 15. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.15 Demo! Architecture Usage
  • 16. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.16 Architecture Plugins: Proxy plugin  MySQL Proxy “is” actually, the Proxy plugin  Accepts connections on its “--proxy-address”  Forwards data to the “--proxy-backend-addresses”  We can provide a Lua script with “--proxy-lua-script”  Exposes hooks to the scripting layer: ➔ connect_server() ➔ read_query() ➔ read_query_result() ➔ ...
  • 17. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.17 Demo! Architecture Plugins: Proxy plugin
  • 18. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.18 Architecture Plugins: Admin plugin  Administration interface  Only authenticated users can use it ➔ --admin-username ➔ --admin-password  Provides information about the proxy server  We must use a Lua script... ➔ --admin-lua-script  … to access the internal components of mysql-proxy
  • 19. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.19 Demo! Architecture Plugins: Admin plugin
  • 20. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.20 Scenarios Query manipulation Let's intercept some user queries and rewrite them...
  • 21. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.21 Scenarios Query manipulation Let's intercept some user queries and rewrite them... rewrite.lua function read_query (packet) if packet:byte() == proxy.COM_QUERY then ... if string.match(string.upper(query), 'foo') then proxy.queries:append(1, string.char(proxy.COM_QUERY) .. "bar") return proxy.PROXY_SEND_QUERY end end end
  • 22. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.22 Demo! Scenarios Query manipulation
  • 23. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.23 Scenarios Query injection Let's inject some useful SQL for certain queries...
  • 24. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.24 Scenarios Query injection Let's inject some useful SQL for certain queries... inject.lua function read_query (packet) ... proxy.queries:append(2, string.char(proxy.COM_QUERY) .. "SELECT CURRENT_USER()", {resultset_is_needed = true}) ... end function read_query_result(inj) ... if (inj.id == 2) then for row in inj.resultset.rows do ... end return proxy.PROXY_IGNORE_RESULT end end
  • 25. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.25 Demo! Scenarios Query injection
  • 26. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.26 Scenarios Load balancing
  • 27. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.27 Scenarios Load balancing ro-pooling.lua function connect_server (packet) --get a connection to a backend... ... end function read_auth_result (auth) --successful connection? Put it on the pool ... end function read_query (packet) --get the first idle server and choose it for backend connection ... end function read_query_result (inj) --manage backends use end function disconnect_client () --manage disconnected clients end
  • 28. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.28 Scenarios R/W splitting
  • 29. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.29 Scenarios R/W splitting rw-splitting.lua function connect_server (packet) --get a connection to a backend... ... end function read_auth_result (auth) --successful connection? Put it on the pool ... end function read_query (packet) --use the tokenizer to check if query is a SELECT. If so pick an idle slave if not pick the master ... end function read_query_result (inj) --manage backends use end function disconnect_client () --manage disconnected clients end
  • 30. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.30 Demo! Scenarios R/W splitting
  • 31. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.31  Used worldwide  Used in production Scenarios
  • 32. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.32 How can we improve? Problems / Solutions Performance issues due to global plugin lock Plugins loaded at start Scripting restricted to Lua Admin plugin limited Code can be optimized 0.8.4 Next... (0.9.0)
  • 33. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.33 Any questions? Download from: http://dev.mysql.com/downloads/mysql-proxy/ Code @ launchpad.net/mysql-proxy mailto: miguel.araujo@oracle.com; jan.kneschke@oracle.com; mark.leith@oracle.com IRC: miguelaraujo / weigon / leithal in #mysql-proxy on irc.freenode.net Thanks!