SlideShare a Scribd company logo
1 of 65
Download to read offline
ProxySQL and the
Tricks Up Its Sleeve
Ideas on How to Manage
Your Database Systems
Who am I?
Jesmar Cannaò
• COO at ProxySQL LLC
• ProxySQL Consultant &
Supporter
• MySQL DBA
ProxySQL LLC
We provide services to help build, support as well as improve the
performance & reliability of your Cloud-Based or On-Premise MySQL
infrastructure:
● ProxySQL Development
● Remote DBRE Consulting
● ProxySQL Support Services
We are hiring!
● Experience coding in C/C++?
● MySQL DBA / Development?
● DevOps / Automation?
● Working remotely?
Application and Database
layers
APPLICATIONS
DATABASES
APPLICATIONS
Database as a Service
(layered)
DATABASES + MANAGER(s)
DAAS – REVERSE PROXY
What is ProxySQL?
MySQL protocol aware data gateway
– Clients connect to ProxySQL
– Requests are evaluated
– Various actions are performed
Visit https://proxysql.com for more information
Main features
● High Availability and Scalability
● seamless failover
● firewall
● query throttling
● query timeout
● query mirroring
● runtime reconfiguration
● Scheduler
● Support for Async Replication, Galera/PXC, Group Replication, Aurora
Main features
● on-the-fly rewrite of queries
● caching reads outside the database
● connection pooling and multiplexing
● complex query routing and r/w split
● load balancing
● real time statistics
● monitoring
● Data masking
● Management of hundreds of backend servers
● Native Clustering
Agenda
• Query routing with thousands of schemas;
• ProxySQL Query firewalling;
• Rebuild environment keeping sensitive data safe;
• Stop having hanging transactions;
• Trigger ProxySQL configuration without writing any
SQL;
• MySQL Replication using ProxySQL;
• ProxySQL integrated Prometheus Exporter;
• Shield your database from spikes in created
Thousands of schemas
and Query Routing
● How to perform fast routing
Routing on user/schema
mysql_query_rules offers routing based on username and schemaname:
INSERT INTO mysql_query_rules (rule_id, username, schemaname,
destination_hostgroup, apply) VALUES
(11, user1, schema1, 10, 1),
(12, user1, schema2, 10, 1),
(13, user1, schema3, 20, 1),
(14, user1, schema4, 20, 1),
(15, user1, schema5, 20, 1);
Routing on user/schema
Same schemas on multiple hostgroups for different users:
INSERT INTO mysql_query_rules (rule_id, username, schemaname,
destination_hostgroup, apply) VALUES
(21, user2, schema1, 30, 1),
(22, user2, schema2, 30, 1),
(23, user2, schema3, 40, 1),
(24, user2, schema4, 40, 1),
(25, user2, schema5, 40, 1);
Routing on user/schema
Does it scale
with thousands
of rules?
Note: Average vs
Maximum latency
mysql_query_rules_fast_routing
CREATE TABLE mysql_query_rules_fast_routing (
username VARCHAR NOT NULL,
schemaname VARCHAR NOT NULL,
flagIN INT NOT NULL DEFAULT 0,
destination_hostgroup INT CHECK (destination_hostgroup >= 0) NOT NULL,
comment VARCHAR NOT NULL,
PRIMARY KEY (username, schemaname, flagIN) )
mysql_query_rules_fast_routing
INSERT INTO mysql_query_rules_fast_routing
(username, schemaname, destination_hostgroup)
VALUES
(user1,schema1,10),(user1,schema2,10),
(user1,schema3,20),(user1,schema4,20),(user1,schema5,20),
(user2,schema1,30),(user2,schema2,30),
(user2,schema3,40),(user2,schema4,40),(user2,schema5,40);
mysql_query_rules_fast_routing
Does it scale with
thousands of rules?
Note: Average vs
Maximum latency
Routing performance comparison
Fast routing and R/W split
INSERT INTO mysql_query_rules(rule_id,match_digest,flagOUT) VALUES
(1,’^SELECT.*FROM tablenameA’,1);
INSERT INTO mysql_query_rules_fast_routing
(username, schemaname, flagIN, destination_hostgroup)
VALUES
(user1,schema1,0,10),(user1,schema1,1,11),
(user1,schema2,0,10),(user1,schema2,1,11),
(user1,schema3,0,20),(user1,schema4,0,20),(user1,schema5,0,20),
(user1,schema3,1,21),(user1,schema4,1,21),(user1,schema5,1,21);
mysql_query_rules_fast_routing
Username is optional:
If a matching username/schemaname is not found, it searches for empty username + schemaname.
INSERT INTO mysql_query_rules_fast_routing
(schemaname, destination_hostgroup) VALUES (schema01,50),
(schema02,50),(schema03,50),(schema04,40),(schema05,60);
Pros: a lot less rows = less memory usage
Cons: double searches
ProxySQL Query Firewalling
● How to block specific queries
● How to build your own Firewall Whitelist
How to block specific queries?
mysql_query_rules offers error_msg:
CREATE TABLE mysql_query_rules (
rule_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 0,
…
error_msg VARCHAR,
…
How to build your own Firewall Whitelist
Whitelist tables:
• mysql_firewall_whitelist_users
• mysql_firewall_whitelist_rules
mysql_firewall_whitelist_users
CREATE TABLE mysql_firewall_whitelist_users (
active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 1,
username VARCHAR NOT NULL,
client_address VARCHAR NOT NULL,
mode VARCHAR CHECK (mode IN
('OFF','DETECTING','PROTECTING')) NOT NULL DEFAULT ('OFF'),
comment VARCHAR NOT NULL,
PRIMARY KEY (username, client_address) )
mysql_firewall_whitelist_users
Mode:
• OFF : allows all queries
• DETECTING: allows all queries, but not whitelisted queries are
logged in error log
• PROTECTING: allows only queries explicitly whitelisted
Where whitelisted?
mysql_firewall_whitelist_rules
Record traffic stats at runtime
CREATE TABLE stats_mysql_query_digest (
hostgroup INT,
schemaname VARCHAR NOT NULL,
username VARCHAR NOT NULL,
client_address VARCHAR NOT NULL,
digest VARCHAR NOT NULL,
digest_text VARCHAR NOT NULL,
count_star INTEGER NOT NULL,
first_seen INTEGER NOT NULL,
last_seen INTEGER NOT NULL,
sum_time INTEGER NOT NULL,
min_time INTEGER NOT NULL,
max_time INTEGER NOT NULL,
sum_rows_affected INTEGER NOT NULL,
sum_rows_sent INTEGER NOT NULL,
PRIMARY KEY(hostgroup, schemaname, username, client_address, digest))
mysql_firewall_whitelist_rules
CREATE TABLE mysql_firewall_whitelist_rules (
active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 1,
username VARCHAR NOT NULL,
client_address VARCHAR NOT NULL,
schemaname VARCHAR NOT NULL,
flagIN INT NOT NULL DEFAULT 0,
digest VARCHAR NOT NULL,
comment VARCHAR NOT NULL,
PRIMARY KEY (username, client_address, schemaname, flagIN, digest)
)
Record traffic stats on disk
CREATE TABLE history_mysql_query_digest (
dump_time INT,
hostgroup INT,
schemaname VARCHAR NOT NULL,
username VARCHAR NOT NULL,
client_address VARCHAR NOT NULL,
digest VARCHAR NOT NULL,
digest_text VARCHAR NOT NULL,
count_star INTEGER NOT NULL,
first_seen INTEGER NOT NULL,
last_seen INTEGER NOT NULL,
sum_time INTEGER NOT NULL,
min_time INTEGER NOT NULL,
max_time INTEGER NOT NULL,
sum_rows_affected INTEGER NOT NULL,
sum_rows_sent INTEGER NOT NULL)
Record traffic stats on disk
● Manually: SAVE MYSQL DIGEST TO DISK
● Automatically:
admin-stats_mysql_query_digest_to_disk
30
Configure firewall users
INSERT INTO mysql_firewall_whitelist_users
(active, username, client_address, mode)
SELECT DISTINCT 1, username, '', 'DETECTING', ''
FROM mysql_users;
31
Configure firewall rules
INSERT INTO mysql_firewall_whitelist_rules
(active, username, client_address, schemaname, flagIN, digest,
comment)
SELECT DISTINCT 1, username, client_address, schemaname, 0,
digest, ''
FROM stats_history.history_mysql_query_digest;
32
Firewall commands
● LOAD MYSQL FIREWALL TO RUNTIME
● SAVE MYSQL FIREWALL TO DISK
● LOAD MYSQL FIREWALL FROM DISK
● SAVE MYSQL FIREWALL FROM RUNTIME
33
Enable firewall globally
SET
mysql-firewall_whitelist_enabled=1;
LOAD MYSQL VARIABLES TO RUNTIME;
SAVE MYSQL VARIABLES TO DISK;
What error shall we send back to the
client?!
The choice is your!
“You shall not pass!” is my preferred, though
System Variable Name mysql-firewall_whitelist_errormsg
Dynamic Yes
Permitted Values Type String
Default Firewall blocked this query
Rebuild environment keeping
sensitive data safe
mysql_query_rules and mysqldump
How the mysql_query_rules would come
handy?
We could use ProxySQL mysql_query_rules to
shield the dataset from accessing sensitive
information
When we are in Dev/Staging/PreProd
environments, we tend to have less stringent
checks and sometime data is saved on
machine with different product owners and less
resources are being spent there…
So maybe it would be better to mask our data
already before making them available to
Solution?!
Again using ProxySQL mysql_query_rules …
but at source!
mysqldump or mydumper for example have very
simple and fixed form of queries like:
SELECT /*!40001 SQL_NO_CACHE */ * FROM `mytable`;
Query rewrite
mysql> SELECT * FROM mysql_query_rules WHERE rule_id=...G
*************************** 1. row ***************************
[..]
match_pattern: ^SELECT * FROM customer
[..]
replace_pattern: SELECT
customer_id,store_id,CONCAT(left(first_name,2),'xxxxxxx')
first_name,CONCAT(left(last_name,2),'xxxxxxxx')
last_name,CONCAT(left(email,2),'xxxxx@xxx',right(email,5))
email,address_id,active,create_date,last_update FROM customer
[..]
1 row in set (0.00 sec)
But what about if I do not want all the
rows?
mysql> SELECT * FROM mysql_query_rules WHERE rule_id=...G
*************************** 1. row ***************************
[..]
match_pattern: $
[..]
replace_pattern: LIMIT 500
[..]
1 row in set (0.00 sec)
Stop having hanging
transactions
mysql-max_transaction_time
mysql-max_transaction_idle_time
mysql-max_transaction_time
It defines the maximum running time for an active transactions: any transaction running for more than this time is
going to be killed.
System Variable Name mysql-max_transaction_time
Dynamic Yes
Permitted Values Type Integer (milliseconds)
Default 14400000 (4 hours)
Minimum 1000 (1 second)
Maximum 1728000000 (20 days)
mysql-max_transaction_idle_time
It defines the maximum idle time for an active transactions: any transaction remaining idle for more than this
time is going to be killed.
System Variable Name mysql-max_transaction_idle_time
Dynamic Yes
Permitted Values Type Integer (milliseconds)
Default 14400000 (4 hours)
Minimum 1000 (1 second)
Maximum 1728000000 (20 days)
Trigger ProxySQL
configuration without writing
any SQL
Via the API interface
Trigger ProxySQL configuration without
writing any SQL
Rest API variables involved
+-----------------------+----------------+
| variable_name | variable_value |
+-----------------------+----------------+
| admin-restapi_enabled | true |
| admin-restapi_port | 6070 |
+-----------------------+----------------+
Examples:
● Add user
● Flush cache
● Change server status
● Load users from a mysql server
● Kill all idle backend connections
● Scrape mysql query digest; etc.
What do I need to configure
CREATE TABLE restapi_routes (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 1,
timeout_ms INTEGER CHECK (timeout_ms>=100 AND
timeout_ms<=100000000) NOT NULL,
method VARCHAR NOT NULL CHECK (UPPER(method) IN ('GET','POST')),
uri VARCHAR NOT NULL,
script VARCHAR NOT NULL,
comment VARCHAR NOT NULL DEFAULT '')
INSERT INTO restapi_routes (active, timeout_ms,
method, uri, script, comment) values
(1,1000,'POST','change_host_status','./scripts/chang
e_host_status.sh','comm');
INSERT INTO restapi_routes (active, timeout_ms,
method, uri, script, comment) VALUES
(1,1000,'GET','flush_query_cache','./scripts/flush_q
uery_cache.sh','comm');
LOAD RESTAPI TO RUNTIME;
SAVE RESTAPI TO DISK;
LOAD RESTAPI FROM DISK;
SAVE RESTAPI FROM RUNTIME;
Who you gonna call?
Flush Query Cache:
curl -i -X GET
http://localhost:6070/sync/flush_query_cache
Who you gonna call?
Change host status:
Assuming local ProxySQL:
curl -i -X POST -d '{ "hostgroup_id": "0", "hostname":
"127.0.0.1", "port": 13306, "status": "OFFLINE_HARD" }'
http://localhost:6070/sync/change_host_status
Specifying server:
curl -i -X POST -d '{ "admin_host": "127.0.0.1", "admin_port":
"6032", "admin_user": "radmin", "admin_pass": "radmin",
"hostgroup_id": "0", "hostname": "127.0.0.1", "port": 13306,
"status": "OFFLINE_HARD" }'
http://localhost:6070/sync/change_host_status
Not going to go through them, but please, have a
look at some of those examples at
https://github.com/sysown/proxysql/tree/v2.x
/scripts
MySQL Replication &
ProxySQL
MySQL Replication vs. ProxySQL
MySQL Replication doesn’t really work when
you want to pass through ProxySQL and let
ProxySQL handle that session and also
considering also the nature of the MySQL
Replication protocol, it is not compatible with
ProxySQL’s functionalities like multiplexing,
query parsing, etc.
… so why you’re telling me
to use ProxySQL?
To make sure you are always connected to
the right node all the time.
To achieve that, configure
mysql_users.fast_forward=1
for the specific user you want to connect
with.
Use cases
• Replication across clusters;
• Debezium;
• Binlog backups;
ProxySQL integrated
Prometheus Exporter
Via the API interface
Prometheus via ProxySQL RestAPI
Once the RestAPI is enables, ProxySQL will
start exposing stats on
proxysql_address:6070/metrics
curl -i -X GET proxysql_address:6070/metric
admin-prometheus_memory_metrics_interval
While some metrics are collected and refreshed in real time, some metrics (currently only memory metrics) are
collected and refreshed only at regular intervals defined by admin-prometheus_memory_metrics_interval
System Variable Name admin-prometheus_memory_metrics_interval
Dynamic Yes
Permitted Values Type Integer (seconds)
Default 61
Minimum 0
Maximum 61
Shield your database from
spikes in created connections
Why? When? How?
• Massive application restart;
• Application peaks due to
events/promotions/etc;
Solution?
• Throttle your API requests; or
• Throttle your connections
mysql-throttle_connections_per_sec_to_hostgroup
System Variable Name mysql-throttle_connections_per_sec_to_hostgroup
Dynamic Yes
Permitted Values Type Integer
Default 1000000
Minimum 1
Maximum 1000000
ProxySQL 2.4
is out!!
Feedback & Thank you!
Visit: https://proxysql.com
Github: https://github.com/sysown/proxysql/
https://github.com/proxysql/
Mailing list: https://groups.google.com/g/proxysql
Twitter: @proxysql
Drop us an email: info@proxysql.com

More Related Content

What's hot

MySQL InnoDB Cluster - Group Replication
MySQL InnoDB Cluster - Group ReplicationMySQL InnoDB Cluster - Group Replication
MySQL InnoDB Cluster - Group ReplicationFrederic Descamps
 
MySQL Database Architectures - High Availability and Disaster Recovery Solution
MySQL Database Architectures - High Availability and Disaster Recovery SolutionMySQL Database Architectures - High Availability and Disaster Recovery Solution
MySQL Database Architectures - High Availability and Disaster Recovery SolutionMiguel Araújo
 
MySQL InnoDB Cluster - A complete High Availability solution for MySQL
MySQL InnoDB Cluster - A complete High Availability solution for MySQLMySQL InnoDB Cluster - A complete High Availability solution for MySQL
MySQL InnoDB Cluster - A complete High Availability solution for MySQLOlivier DASINI
 
MySQL Performance Schema in Action
MySQL Performance Schema in ActionMySQL Performance Schema in Action
MySQL Performance Schema in ActionSveta Smirnova
 
ProxySQL High Availability (Clustering)
ProxySQL High Availability (Clustering)ProxySQL High Availability (Clustering)
ProxySQL High Availability (Clustering)Mydbops
 
State of the Dolphin - May 2022
State of the Dolphin - May 2022State of the Dolphin - May 2022
State of the Dolphin - May 2022Frederic Descamps
 
ProxySQL on Kubernetes
ProxySQL on KubernetesProxySQL on Kubernetes
ProxySQL on KubernetesRené Cannaò
 
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11Kenny Gryp
 
Mvcc in postgreSQL 권건우
Mvcc in postgreSQL 권건우Mvcc in postgreSQL 권건우
Mvcc in postgreSQL 권건우PgDay.Seoul
 
JSON improvements in MySQL 8.0
JSON improvements in MySQL 8.0JSON improvements in MySQL 8.0
JSON improvements in MySQL 8.0Mydbops
 
PostgreSQL HA
PostgreSQL   HAPostgreSQL   HA
PostgreSQL HAharoonm
 
MMUG18 - MySQL Failover and Orchestrator
MMUG18 - MySQL Failover and OrchestratorMMUG18 - MySQL Failover and Orchestrator
MMUG18 - MySQL Failover and OrchestratorSimon J Mudd
 
MySQL Database Architectures - InnoDB ReplicaSet & Cluster
MySQL Database Architectures - InnoDB ReplicaSet & ClusterMySQL Database Architectures - InnoDB ReplicaSet & Cluster
MySQL Database Architectures - InnoDB ReplicaSet & ClusterKenny Gryp
 
MySQL/MariaDB Proxy Software Test
MySQL/MariaDB Proxy Software TestMySQL/MariaDB Proxy Software Test
MySQL/MariaDB Proxy Software TestI Goo Lee
 
MySQL InnoDB Cluster - Advanced Configuration & Operations
MySQL InnoDB Cluster - Advanced Configuration & OperationsMySQL InnoDB Cluster - Advanced Configuration & Operations
MySQL InnoDB Cluster - Advanced Configuration & OperationsFrederic Descamps
 
The Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication TutorialThe Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication TutorialJean-François Gagné
 

What's hot (20)

Query logging with proxysql
Query logging with proxysqlQuery logging with proxysql
Query logging with proxysql
 
MySQL Router REST API
MySQL Router REST APIMySQL Router REST API
MySQL Router REST API
 
MySQL InnoDB Cluster - Group Replication
MySQL InnoDB Cluster - Group ReplicationMySQL InnoDB Cluster - Group Replication
MySQL InnoDB Cluster - Group Replication
 
MySQL Database Architectures - High Availability and Disaster Recovery Solution
MySQL Database Architectures - High Availability and Disaster Recovery SolutionMySQL Database Architectures - High Availability and Disaster Recovery Solution
MySQL Database Architectures - High Availability and Disaster Recovery Solution
 
ProxySQL at Scale on AWS.pdf
ProxySQL at Scale on AWS.pdfProxySQL at Scale on AWS.pdf
ProxySQL at Scale on AWS.pdf
 
Planning for Disaster Recovery (DR) with Galera Cluster
Planning for Disaster Recovery (DR) with Galera ClusterPlanning for Disaster Recovery (DR) with Galera Cluster
Planning for Disaster Recovery (DR) with Galera Cluster
 
MySQL InnoDB Cluster - A complete High Availability solution for MySQL
MySQL InnoDB Cluster - A complete High Availability solution for MySQLMySQL InnoDB Cluster - A complete High Availability solution for MySQL
MySQL InnoDB Cluster - A complete High Availability solution for MySQL
 
MySQL Performance Schema in Action
MySQL Performance Schema in ActionMySQL Performance Schema in Action
MySQL Performance Schema in Action
 
ProxySQL High Availability (Clustering)
ProxySQL High Availability (Clustering)ProxySQL High Availability (Clustering)
ProxySQL High Availability (Clustering)
 
State of the Dolphin - May 2022
State of the Dolphin - May 2022State of the Dolphin - May 2022
State of the Dolphin - May 2022
 
ProxySQL on Kubernetes
ProxySQL on KubernetesProxySQL on Kubernetes
ProxySQL on Kubernetes
 
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
 
Mvcc in postgreSQL 권건우
Mvcc in postgreSQL 권건우Mvcc in postgreSQL 권건우
Mvcc in postgreSQL 권건우
 
JSON improvements in MySQL 8.0
JSON improvements in MySQL 8.0JSON improvements in MySQL 8.0
JSON improvements in MySQL 8.0
 
PostgreSQL HA
PostgreSQL   HAPostgreSQL   HA
PostgreSQL HA
 
MMUG18 - MySQL Failover and Orchestrator
MMUG18 - MySQL Failover and OrchestratorMMUG18 - MySQL Failover and Orchestrator
MMUG18 - MySQL Failover and Orchestrator
 
MySQL Database Architectures - InnoDB ReplicaSet & Cluster
MySQL Database Architectures - InnoDB ReplicaSet & ClusterMySQL Database Architectures - InnoDB ReplicaSet & Cluster
MySQL Database Architectures - InnoDB ReplicaSet & Cluster
 
MySQL/MariaDB Proxy Software Test
MySQL/MariaDB Proxy Software TestMySQL/MariaDB Proxy Software Test
MySQL/MariaDB Proxy Software Test
 
MySQL InnoDB Cluster - Advanced Configuration & Operations
MySQL InnoDB Cluster - Advanced Configuration & OperationsMySQL InnoDB Cluster - Advanced Configuration & Operations
MySQL InnoDB Cluster - Advanced Configuration & Operations
 
The Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication TutorialThe Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication Tutorial
 

Similar to ProxySQL and the Tricks Up Its Sleeve

Fortify aws aurora_proxy
Fortify aws aurora_proxyFortify aws aurora_proxy
Fortify aws aurora_proxyMarco Tusa
 
Fortify aws aurora_proxy_2019_pleu
Fortify aws aurora_proxy_2019_pleuFortify aws aurora_proxy_2019_pleu
Fortify aws aurora_proxy_2019_pleuMarco Tusa
 
Inexpensive Datamasking for MySQL with ProxySQL — Data Anonymization for Deve...
Inexpensive Datamasking for MySQL with ProxySQL — Data Anonymization for Deve...Inexpensive Datamasking for MySQL with ProxySQL — Data Anonymization for Deve...
Inexpensive Datamasking for MySQL with ProxySQL — Data Anonymization for Deve...Ontico
 
AZMS PRESENTATION.pptx
AZMS PRESENTATION.pptxAZMS PRESENTATION.pptx
AZMS PRESENTATION.pptxSonuShaw16
 
Confoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New FeaturesConfoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New FeaturesDave Stokes
 
Built-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsBuilt-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsUlf Wendel
 
Scaling MySQL Strategies for Developers
Scaling MySQL Strategies for DevelopersScaling MySQL Strategies for Developers
Scaling MySQL Strategies for DevelopersJonathan Levin
 
Data Handning with Sqlite for Android
Data Handning with Sqlite for AndroidData Handning with Sqlite for Android
Data Handning with Sqlite for AndroidJakir Hossain
 
New features in ProxySQL 2.0 (updated to 2.0.9) by Rene Cannao (ProxySQL)
New features in ProxySQL 2.0 (updated to 2.0.9) by Rene Cannao (ProxySQL)New features in ProxySQL 2.0 (updated to 2.0.9) by Rene Cannao (ProxySQL)
New features in ProxySQL 2.0 (updated to 2.0.9) by Rene Cannao (ProxySQL)Altinity Ltd
 
Memcached Functions For My Sql Seemless Caching In My Sql
Memcached Functions For My Sql Seemless Caching In My SqlMemcached Functions For My Sql Seemless Caching In My Sql
Memcached Functions For My Sql Seemless Caching In My SqlMySQLConference
 
Web app development_crud_13
Web app development_crud_13Web app development_crud_13
Web app development_crud_13Hassen Poreya
 
Designer's Favorite New Features in SQLServer
Designer's Favorite New Features in SQLServerDesigner's Favorite New Features in SQLServer
Designer's Favorite New Features in SQLServerKaren Lopez
 
Mysql database basic user guide
Mysql database basic user guideMysql database basic user guide
Mysql database basic user guidePoguttuezhiniVP
 
HandsOn ProxySQL Tutorial - PLSC18
HandsOn ProxySQL Tutorial - PLSC18HandsOn ProxySQL Tutorial - PLSC18
HandsOn ProxySQL Tutorial - PLSC18Derek Downey
 

Similar to ProxySQL and the Tricks Up Its Sleeve (20)

Fortify aws aurora_proxy
Fortify aws aurora_proxyFortify aws aurora_proxy
Fortify aws aurora_proxy
 
Fortify aws aurora_proxy_2019_pleu
Fortify aws aurora_proxy_2019_pleuFortify aws aurora_proxy_2019_pleu
Fortify aws aurora_proxy_2019_pleu
 
Inexpensive Datamasking for MySQL with ProxySQL — Data Anonymization for Deve...
Inexpensive Datamasking for MySQL with ProxySQL — Data Anonymization for Deve...Inexpensive Datamasking for MySQL with ProxySQL — Data Anonymization for Deve...
Inexpensive Datamasking for MySQL with ProxySQL — Data Anonymization for Deve...
 
MySQL Quick Dive
MySQL Quick DiveMySQL Quick Dive
MySQL Quick Dive
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
 
AZMS PRESENTATION.pptx
AZMS PRESENTATION.pptxAZMS PRESENTATION.pptx
AZMS PRESENTATION.pptx
 
Confoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New FeaturesConfoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New Features
 
Built-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsBuilt-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIs
 
The Operation CloudBurst Attack
The Operation CloudBurst AttackThe Operation CloudBurst Attack
The Operation CloudBurst Attack
 
Stored procedures
Stored proceduresStored procedures
Stored procedures
 
Scaling MySQL Strategies for Developers
Scaling MySQL Strategies for DevelopersScaling MySQL Strategies for Developers
Scaling MySQL Strategies for Developers
 
Data Handning with Sqlite for Android
Data Handning with Sqlite for AndroidData Handning with Sqlite for Android
Data Handning with Sqlite for Android
 
New features in ProxySQL 2.0 (updated to 2.0.9) by Rene Cannao (ProxySQL)
New features in ProxySQL 2.0 (updated to 2.0.9) by Rene Cannao (ProxySQL)New features in ProxySQL 2.0 (updated to 2.0.9) by Rene Cannao (ProxySQL)
New features in ProxySQL 2.0 (updated to 2.0.9) by Rene Cannao (ProxySQL)
 
Memcached Functions For My Sql Seemless Caching In My Sql
Memcached Functions For My Sql Seemless Caching In My SqlMemcached Functions For My Sql Seemless Caching In My Sql
Memcached Functions For My Sql Seemless Caching In My Sql
 
Web app development_crud_13
Web app development_crud_13Web app development_crud_13
Web app development_crud_13
 
Designer's Favorite New Features in SQLServer
Designer's Favorite New Features in SQLServerDesigner's Favorite New Features in SQLServer
Designer's Favorite New Features in SQLServer
 
Mysql database basic user guide
Mysql database basic user guideMysql database basic user guide
Mysql database basic user guide
 
HandsOn ProxySQL Tutorial - PLSC18
HandsOn ProxySQL Tutorial - PLSC18HandsOn ProxySQL Tutorial - PLSC18
HandsOn ProxySQL Tutorial - PLSC18
 
Mysql tracing
Mysql tracingMysql tracing
Mysql tracing
 
Mysql tracing
Mysql tracingMysql tracing
Mysql tracing
 

Recently uploaded

A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Fact vs. Fiction: Autodetecting Hallucinations in LLMs
Fact vs. Fiction: Autodetecting Hallucinations in LLMsFact vs. Fiction: Autodetecting Hallucinations in LLMs
Fact vs. Fiction: Autodetecting Hallucinations in LLMsZilliz
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 

Recently uploaded (20)

A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Fact vs. Fiction: Autodetecting Hallucinations in LLMs
Fact vs. Fiction: Autodetecting Hallucinations in LLMsFact vs. Fiction: Autodetecting Hallucinations in LLMs
Fact vs. Fiction: Autodetecting Hallucinations in LLMs
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 

ProxySQL and the Tricks Up Its Sleeve

  • 1. ProxySQL and the Tricks Up Its Sleeve Ideas on How to Manage Your Database Systems
  • 2. Who am I? Jesmar Cannaò • COO at ProxySQL LLC • ProxySQL Consultant & Supporter • MySQL DBA
  • 3. ProxySQL LLC We provide services to help build, support as well as improve the performance & reliability of your Cloud-Based or On-Premise MySQL infrastructure: ● ProxySQL Development ● Remote DBRE Consulting ● ProxySQL Support Services
  • 4. We are hiring! ● Experience coding in C/C++? ● MySQL DBA / Development? ● DevOps / Automation? ● Working remotely?
  • 6. APPLICATIONS Database as a Service (layered) DATABASES + MANAGER(s) DAAS – REVERSE PROXY
  • 7. What is ProxySQL? MySQL protocol aware data gateway – Clients connect to ProxySQL – Requests are evaluated – Various actions are performed Visit https://proxysql.com for more information
  • 8. Main features ● High Availability and Scalability ● seamless failover ● firewall ● query throttling ● query timeout ● query mirroring ● runtime reconfiguration ● Scheduler ● Support for Async Replication, Galera/PXC, Group Replication, Aurora
  • 9. Main features ● on-the-fly rewrite of queries ● caching reads outside the database ● connection pooling and multiplexing ● complex query routing and r/w split ● load balancing ● real time statistics ● monitoring ● Data masking ● Management of hundreds of backend servers ● Native Clustering
  • 10. Agenda • Query routing with thousands of schemas; • ProxySQL Query firewalling; • Rebuild environment keeping sensitive data safe; • Stop having hanging transactions; • Trigger ProxySQL configuration without writing any SQL; • MySQL Replication using ProxySQL; • ProxySQL integrated Prometheus Exporter; • Shield your database from spikes in created
  • 11. Thousands of schemas and Query Routing ● How to perform fast routing
  • 12. Routing on user/schema mysql_query_rules offers routing based on username and schemaname: INSERT INTO mysql_query_rules (rule_id, username, schemaname, destination_hostgroup, apply) VALUES (11, user1, schema1, 10, 1), (12, user1, schema2, 10, 1), (13, user1, schema3, 20, 1), (14, user1, schema4, 20, 1), (15, user1, schema5, 20, 1);
  • 13. Routing on user/schema Same schemas on multiple hostgroups for different users: INSERT INTO mysql_query_rules (rule_id, username, schemaname, destination_hostgroup, apply) VALUES (21, user2, schema1, 30, 1), (22, user2, schema2, 30, 1), (23, user2, schema3, 40, 1), (24, user2, schema4, 40, 1), (25, user2, schema5, 40, 1);
  • 14. Routing on user/schema Does it scale with thousands of rules? Note: Average vs Maximum latency
  • 15. mysql_query_rules_fast_routing CREATE TABLE mysql_query_rules_fast_routing ( username VARCHAR NOT NULL, schemaname VARCHAR NOT NULL, flagIN INT NOT NULL DEFAULT 0, destination_hostgroup INT CHECK (destination_hostgroup >= 0) NOT NULL, comment VARCHAR NOT NULL, PRIMARY KEY (username, schemaname, flagIN) )
  • 16. mysql_query_rules_fast_routing INSERT INTO mysql_query_rules_fast_routing (username, schemaname, destination_hostgroup) VALUES (user1,schema1,10),(user1,schema2,10), (user1,schema3,20),(user1,schema4,20),(user1,schema5,20), (user2,schema1,30),(user2,schema2,30), (user2,schema3,40),(user2,schema4,40),(user2,schema5,40);
  • 17. mysql_query_rules_fast_routing Does it scale with thousands of rules? Note: Average vs Maximum latency
  • 19. Fast routing and R/W split INSERT INTO mysql_query_rules(rule_id,match_digest,flagOUT) VALUES (1,’^SELECT.*FROM tablenameA’,1); INSERT INTO mysql_query_rules_fast_routing (username, schemaname, flagIN, destination_hostgroup) VALUES (user1,schema1,0,10),(user1,schema1,1,11), (user1,schema2,0,10),(user1,schema2,1,11), (user1,schema3,0,20),(user1,schema4,0,20),(user1,schema5,0,20), (user1,schema3,1,21),(user1,schema4,1,21),(user1,schema5,1,21);
  • 20. mysql_query_rules_fast_routing Username is optional: If a matching username/schemaname is not found, it searches for empty username + schemaname. INSERT INTO mysql_query_rules_fast_routing (schemaname, destination_hostgroup) VALUES (schema01,50), (schema02,50),(schema03,50),(schema04,40),(schema05,60); Pros: a lot less rows = less memory usage Cons: double searches
  • 21. ProxySQL Query Firewalling ● How to block specific queries ● How to build your own Firewall Whitelist
  • 22. How to block specific queries? mysql_query_rules offers error_msg: CREATE TABLE mysql_query_rules ( rule_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 0, … error_msg VARCHAR, …
  • 23. How to build your own Firewall Whitelist Whitelist tables: • mysql_firewall_whitelist_users • mysql_firewall_whitelist_rules
  • 24. mysql_firewall_whitelist_users CREATE TABLE mysql_firewall_whitelist_users ( active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 1, username VARCHAR NOT NULL, client_address VARCHAR NOT NULL, mode VARCHAR CHECK (mode IN ('OFF','DETECTING','PROTECTING')) NOT NULL DEFAULT ('OFF'), comment VARCHAR NOT NULL, PRIMARY KEY (username, client_address) )
  • 25. mysql_firewall_whitelist_users Mode: • OFF : allows all queries • DETECTING: allows all queries, but not whitelisted queries are logged in error log • PROTECTING: allows only queries explicitly whitelisted Where whitelisted? mysql_firewall_whitelist_rules
  • 26. Record traffic stats at runtime CREATE TABLE stats_mysql_query_digest ( hostgroup INT, schemaname VARCHAR NOT NULL, username VARCHAR NOT NULL, client_address VARCHAR NOT NULL, digest VARCHAR NOT NULL, digest_text VARCHAR NOT NULL, count_star INTEGER NOT NULL, first_seen INTEGER NOT NULL, last_seen INTEGER NOT NULL, sum_time INTEGER NOT NULL, min_time INTEGER NOT NULL, max_time INTEGER NOT NULL, sum_rows_affected INTEGER NOT NULL, sum_rows_sent INTEGER NOT NULL, PRIMARY KEY(hostgroup, schemaname, username, client_address, digest))
  • 27. mysql_firewall_whitelist_rules CREATE TABLE mysql_firewall_whitelist_rules ( active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 1, username VARCHAR NOT NULL, client_address VARCHAR NOT NULL, schemaname VARCHAR NOT NULL, flagIN INT NOT NULL DEFAULT 0, digest VARCHAR NOT NULL, comment VARCHAR NOT NULL, PRIMARY KEY (username, client_address, schemaname, flagIN, digest) )
  • 28. Record traffic stats on disk CREATE TABLE history_mysql_query_digest ( dump_time INT, hostgroup INT, schemaname VARCHAR NOT NULL, username VARCHAR NOT NULL, client_address VARCHAR NOT NULL, digest VARCHAR NOT NULL, digest_text VARCHAR NOT NULL, count_star INTEGER NOT NULL, first_seen INTEGER NOT NULL, last_seen INTEGER NOT NULL, sum_time INTEGER NOT NULL, min_time INTEGER NOT NULL, max_time INTEGER NOT NULL, sum_rows_affected INTEGER NOT NULL, sum_rows_sent INTEGER NOT NULL)
  • 29. Record traffic stats on disk ● Manually: SAVE MYSQL DIGEST TO DISK ● Automatically: admin-stats_mysql_query_digest_to_disk
  • 30. 30 Configure firewall users INSERT INTO mysql_firewall_whitelist_users (active, username, client_address, mode) SELECT DISTINCT 1, username, '', 'DETECTING', '' FROM mysql_users;
  • 31. 31 Configure firewall rules INSERT INTO mysql_firewall_whitelist_rules (active, username, client_address, schemaname, flagIN, digest, comment) SELECT DISTINCT 1, username, client_address, schemaname, 0, digest, '' FROM stats_history.history_mysql_query_digest;
  • 32. 32 Firewall commands ● LOAD MYSQL FIREWALL TO RUNTIME ● SAVE MYSQL FIREWALL TO DISK ● LOAD MYSQL FIREWALL FROM DISK ● SAVE MYSQL FIREWALL FROM RUNTIME
  • 33. 33 Enable firewall globally SET mysql-firewall_whitelist_enabled=1; LOAD MYSQL VARIABLES TO RUNTIME; SAVE MYSQL VARIABLES TO DISK;
  • 34. What error shall we send back to the client?! The choice is your! “You shall not pass!” is my preferred, though System Variable Name mysql-firewall_whitelist_errormsg Dynamic Yes Permitted Values Type String Default Firewall blocked this query
  • 35. Rebuild environment keeping sensitive data safe mysql_query_rules and mysqldump
  • 36. How the mysql_query_rules would come handy? We could use ProxySQL mysql_query_rules to shield the dataset from accessing sensitive information
  • 37. When we are in Dev/Staging/PreProd environments, we tend to have less stringent checks and sometime data is saved on machine with different product owners and less resources are being spent there… So maybe it would be better to mask our data already before making them available to
  • 38. Solution?! Again using ProxySQL mysql_query_rules … but at source! mysqldump or mydumper for example have very simple and fixed form of queries like: SELECT /*!40001 SQL_NO_CACHE */ * FROM `mytable`;
  • 39. Query rewrite mysql> SELECT * FROM mysql_query_rules WHERE rule_id=...G *************************** 1. row *************************** [..] match_pattern: ^SELECT * FROM customer [..] replace_pattern: SELECT customer_id,store_id,CONCAT(left(first_name,2),'xxxxxxx') first_name,CONCAT(left(last_name,2),'xxxxxxxx') last_name,CONCAT(left(email,2),'xxxxx@xxx',right(email,5)) email,address_id,active,create_date,last_update FROM customer [..] 1 row in set (0.00 sec)
  • 40. But what about if I do not want all the rows? mysql> SELECT * FROM mysql_query_rules WHERE rule_id=...G *************************** 1. row *************************** [..] match_pattern: $ [..] replace_pattern: LIMIT 500 [..] 1 row in set (0.00 sec)
  • 42. mysql-max_transaction_time It defines the maximum running time for an active transactions: any transaction running for more than this time is going to be killed. System Variable Name mysql-max_transaction_time Dynamic Yes Permitted Values Type Integer (milliseconds) Default 14400000 (4 hours) Minimum 1000 (1 second) Maximum 1728000000 (20 days)
  • 43. mysql-max_transaction_idle_time It defines the maximum idle time for an active transactions: any transaction remaining idle for more than this time is going to be killed. System Variable Name mysql-max_transaction_idle_time Dynamic Yes Permitted Values Type Integer (milliseconds) Default 14400000 (4 hours) Minimum 1000 (1 second) Maximum 1728000000 (20 days)
  • 44. Trigger ProxySQL configuration without writing any SQL Via the API interface
  • 45. Trigger ProxySQL configuration without writing any SQL Rest API variables involved +-----------------------+----------------+ | variable_name | variable_value | +-----------------------+----------------+ | admin-restapi_enabled | true | | admin-restapi_port | 6070 | +-----------------------+----------------+
  • 46. Examples: ● Add user ● Flush cache ● Change server status ● Load users from a mysql server ● Kill all idle backend connections ● Scrape mysql query digest; etc.
  • 47. What do I need to configure CREATE TABLE restapi_routes ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 1, timeout_ms INTEGER CHECK (timeout_ms>=100 AND timeout_ms<=100000000) NOT NULL, method VARCHAR NOT NULL CHECK (UPPER(method) IN ('GET','POST')), uri VARCHAR NOT NULL, script VARCHAR NOT NULL, comment VARCHAR NOT NULL DEFAULT '')
  • 48. INSERT INTO restapi_routes (active, timeout_ms, method, uri, script, comment) values (1,1000,'POST','change_host_status','./scripts/chang e_host_status.sh','comm'); INSERT INTO restapi_routes (active, timeout_ms, method, uri, script, comment) VALUES (1,1000,'GET','flush_query_cache','./scripts/flush_q uery_cache.sh','comm');
  • 49. LOAD RESTAPI TO RUNTIME; SAVE RESTAPI TO DISK; LOAD RESTAPI FROM DISK; SAVE RESTAPI FROM RUNTIME;
  • 50. Who you gonna call? Flush Query Cache: curl -i -X GET http://localhost:6070/sync/flush_query_cache
  • 51. Who you gonna call? Change host status: Assuming local ProxySQL: curl -i -X POST -d '{ "hostgroup_id": "0", "hostname": "127.0.0.1", "port": 13306, "status": "OFFLINE_HARD" }' http://localhost:6070/sync/change_host_status Specifying server: curl -i -X POST -d '{ "admin_host": "127.0.0.1", "admin_port": "6032", "admin_user": "radmin", "admin_pass": "radmin", "hostgroup_id": "0", "hostname": "127.0.0.1", "port": 13306, "status": "OFFLINE_HARD" }' http://localhost:6070/sync/change_host_status
  • 52. Not going to go through them, but please, have a look at some of those examples at https://github.com/sysown/proxysql/tree/v2.x /scripts
  • 54. MySQL Replication vs. ProxySQL MySQL Replication doesn’t really work when you want to pass through ProxySQL and let ProxySQL handle that session and also considering also the nature of the MySQL Replication protocol, it is not compatible with ProxySQL’s functionalities like multiplexing, query parsing, etc.
  • 55. … so why you’re telling me to use ProxySQL? To make sure you are always connected to the right node all the time. To achieve that, configure mysql_users.fast_forward=1 for the specific user you want to connect with.
  • 56. Use cases • Replication across clusters; • Debezium; • Binlog backups;
  • 58. Prometheus via ProxySQL RestAPI Once the RestAPI is enables, ProxySQL will start exposing stats on proxysql_address:6070/metrics curl -i -X GET proxysql_address:6070/metric
  • 59. admin-prometheus_memory_metrics_interval While some metrics are collected and refreshed in real time, some metrics (currently only memory metrics) are collected and refreshed only at regular intervals defined by admin-prometheus_memory_metrics_interval System Variable Name admin-prometheus_memory_metrics_interval Dynamic Yes Permitted Values Type Integer (seconds) Default 61 Minimum 0 Maximum 61
  • 60. Shield your database from spikes in created connections
  • 61. Why? When? How? • Massive application restart; • Application peaks due to events/promotions/etc;
  • 62. Solution? • Throttle your API requests; or • Throttle your connections
  • 63. mysql-throttle_connections_per_sec_to_hostgroup System Variable Name mysql-throttle_connections_per_sec_to_hostgroup Dynamic Yes Permitted Values Type Integer Default 1000000 Minimum 1 Maximum 1000000
  • 65. Feedback & Thank you! Visit: https://proxysql.com Github: https://github.com/sysown/proxysql/ https://github.com/proxysql/ Mailing list: https://groups.google.com/g/proxysql Twitter: @proxysql Drop us an email: info@proxysql.com