High-performance MySQL proxy with a GPL license.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Go to file
René Cannaò 10ff1322ba
Merge pull request #5386 from sysown/v3.0-MCP_multi
6 hours ago
.github update GH-Actions triggers 5 months ago
RAG_POC RAG: Improve system prompt, replace hardcoded values with env vars 2 weeks ago
binaries
common_mk build: replace grep -oP with sed -E for macOS compatibility 2 weeks ago
deps Add notes about Valgrind and SQLite memory management 5 days ago
diamond
doc mcp discovery: enforce target-scoped run model and add protocol-aware static harvesting (mysql+pgsql) 19 hours ago
docker build_deps with PROXYSQLGENAI=1 when needed 1 week ago
etc fix bash scripts shebang 2 years ago
genai_prototype Merge branch 'v3.1-vec' into v3.1-MCP1 1 month ago
include Merge pull request #5386 from sysown/v3.0-MCP_multi 6 hours ago
lib Merge pull request #5386 from sysown/v3.0-MCP_multi 6 hours ago
microbench Changes done: 1 year ago
notes
scripts mcp tests: add phase-B TAP coverage and optional real Claude CLI E2E runner 18 hours ago
src MCP: add target-aware rules/stats tests, explain_sql rule coverage, and AI local docker TAP infra 1 day ago
systemd/system
test Merge pull request #5386 from sysown/v3.0-MCP_multi 6 hours ago
tools reduce duplication in makefiles, use include for common stuff 4 months ago
.aider.conf.yml .aider file 5 months ago
.gitignore Organize RAG test files properly and update .gitignore 4 weeks ago
Aurora_Automated_Testing.md
CHANGELOG.md CHANGELOG update 5 months ago
CONTRIBUTING.md Add CONTRIBUTING.md guide for community contributors 2 months ago
FAQ.md
INSTALL.md Updated macOS build instructions in INSTALL.md and added doc/BUILD-MACOS.md 4 weeks ago
LICENSE
Makefile Apply AI agent review fixes to PR #5374 4 days ago
ProxySQL-3.0.4-Release-Notes.md [skip-ci] Add release notes automation tools 2 months ago
RAG_COMPLETION_SUMMARY.md feat: Complete RAG implementation according to blueprint specifications 4 weeks ago
RAG_FILE_SUMMARY.md feat: Implement RAG (Retrieval-Augmented Generation) subsystem 4 weeks ago
RAG_IMPLEMENTATION_COMPLETE.md feat: Implement RAG (Retrieval-Augmented Generation) subsystem 4 weeks ago
RAG_IMPLEMENTATION_SUMMARY.md feat: Complete RAG implementation according to blueprint specifications 4 weeks ago
README.md Add Table of Contents 2 months ago
RELEASE_NOTES_WORKFLOW.md [skip-ci] Add release notes automation tools 2 months ago
RUNNING.md
Read_Only_Testing.md Adding a simulator for read_only test 5 years ago
bounty.md
build_images.py
compile_examples.txt
docker-compose.yml update fedora build image versions 1 week ago
proxysql-tests.ini.example
proxysql_notes.txt Separate query cache metrics for MySQL and PostgreSQL 4 months ago
scenarios.py
simple_discovery.py Add multi-agent database discovery system 1 month ago

README.md

CI-selftests CI-repltests CodeQL Package-Build

ProxySQL

Table of Contents

Introduction

ProxySQL is a high-performance, high-availability, protocol-aware proxy for MySQL and its forks (such as Percona Server and MariaDB), as well as PostgreSQL. All the while getting the unlimited freedom that comes with a GPL license.

Its development is driven by the lack of open source proxies that provide high performance.

Useful links

Getting started

Installation

Released packages can be found here: https://github.com/sysown/proxysql/releases

Just download a package and use your systems package manager to install it:

wget https://github.com/sysown/proxysql/releases/download/v3.0.4/proxysql_3.0.4-ubuntu24_amd64.deb
dpkg -i proxysql_3.0.4-ubuntu24_amd64.deb

Alternatively you can also use the available repositories:

Ubuntu / Debian:

Adding repository:

apt-get update && apt-get install -y --no-install-recommends lsb-release wget apt-transport-https ca-certificates
wget -nv -O /etc/apt/trusted.gpg.d/proxysql-3.0.x-keyring.gpg 'https://repo.proxysql.com/ProxySQL/proxysql-3.0.x/repo_pub_key.gpg'
echo "deb https://repo.proxysql.com/ProxySQL/proxysql-3.0.x/$(lsb_release -sc)/ ./" | tee /etc/apt/sources.list.d/proxysql.list

Installing:

apt-get update
apt-get install proxysql OR apt-get install proxysql=version

Red Hat / CentOS:

Adding repository:

cat > /etc/yum.repos.d/proxysql.repo << EOF
[proxysql]
name=ProxySQL YUM repository
baseurl=https://repo.proxysql.com/ProxySQL/proxysql-3.0.x/centos/\$releasever
gpgcheck=1
gpgkey=https://repo.proxysql.com/ProxySQL/proxysql-3.0.x/repo_pub_key
EOF

Installing:

yum install proxysql OR yum install proxysql-version

Amazon Linux:

Adding repository:

cat > /etc/yum.repos.d/proxysql.repo << EOF
[proxysql]
name=ProxySQL YUM repository
baseurl=https://repo.proxysql.com/ProxySQL/proxysql-3.0.x/centos/8
gpgcheck=1
gpgkey=https://repo.proxysql.com/ProxySQL/proxysql-3.0.x/repo_pub_key
EOF

Installing:

yum install proxysql OR yum install proxysql-version

Almalinux:

Adding repository:

cat > /etc/yum.repos.d/proxysql.repo << EOF
[proxysql]
name=ProxySQL YUM repository
baseurl=https://repo.proxysql.com/ProxySQL/proxysql-3.0.x/almalinux/\$releasever
gpgcheck=1
gpgkey=https://repo.proxysql.com/ProxySQL/proxysql-3.0.x/repo_pub_key
EOF

Installing:

yum install proxysql OR yum install proxysql-version

OpenSUSE:

Adding repository:

cat > /etc/zypp/repos.d/proxysql.repo << EOF
[proxysql]
name=ProxySQL Zypper repository
enabled=1
autorefresh=0
baseurl=https://repo.proxysql.com/ProxySQL/proxysql-3.0.x/opensuse/\$releasever_major
gpgcheck=1
EOF

or

zypper addrepo -g -n 'ProxySQL Zypper repository' 'https://repo.proxysql.com/ProxySQL/proxysql-3.0.x/opensuse/$releasever_major' proxysql

Installing:

yum install proxysql OR yum install proxysql-version

FreeBSD:

Installing (via pkg):

pkg install proxysql

Installing (via ports):

cd /usr/ports/databases/proxysql/ && make install clean

Service management

Once the software is installed, you can use the service command to control the process:

Starting ProxySQL:

service proxysql start

Stopping ProxySQL:

service proxysql stop

Or alternatively via the Admin interface (MySQL admin example):

$ mysql -u admin -padmin -h 127.0.0.1 -P6032 --prompt='Admin> '
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 4
Server version: 5.5.30 (ProxySQL Admin Module)

Copyright (c) 2000, 2016, 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> proxysql stop

For PostgreSQL admin interface the same Admin commands apply and the admin port defaults to 6132. You can connect using the psql client as follows:

$ export PGPASSWORD=admin
$ psql -U admin -h 127.0.0.1 -p6132
psql (17.4 (Ubuntu 17.4-1.pgdg22.04+2), server 16.1)
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off, ALPN: none)
Type "help" for help.

admin=# proxysql stop

(The examples above show the Admin interface workflow - the Admin SQL commands are the same for both MySQL and PostgreSQL modes.)

Restarting ProxySQL:

service proxysql restart

Or alternatively via the Admin interface (MySQL example):

$ mysql -u admin -padmin -h 127.0.0.1 -P6032 --prompt='Admin> '
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 4
Server version: 5.5.30 (ProxySQL Admin Module)

Copyright (c) 2000, 2016, 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> proxysql restart

Or via the PostgreSQL admin port:

$ export PGPASSWORD=admin
$ psql -U admin -h 127.0.0.1 -p6132
psql (17.4 (Ubuntu 17.4-1.pgdg22.04+2), server 16.1)
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off, ALPN: none)
Type "help" for help.

admin=# proxysql restart

Reinitializing ProxySQL from the config file (after first startup the DB file is used instead of the config file):

# If you are using the init script run:
/etc/init.d/proxysql initial
# or
service proxysql initial
 
# If you are using the systemd unit file run:
systemctl start proxysql-initial
# or
service proxysql-initial start

Upgrades

Just install the new package and restart ProxySQL:

wget https://github.com/sysown/proxysql/releases/download/v3.0.4/proxysql_3.0.4-ubuntu24_amd64.deb
dpkg -i proxysql_3.0.4-ubuntu24_amd64.deb
service proxysql restart

How to check the ProxySQL version

$ proxysql --version
ProxySQL version 3.0.4-162-gfaa64a5, codename Truls

A debug version has _DEBUG in its version string. It is slower than non-debug version, but easier to debug in case of failures.

$ proxysql --version
ProxySQL version 3.0.4-162-gfaa64a5_DEBUG, codename Truls

Configuring ProxySQL via the admin interface

First of all, bear in mind that the best way to configure ProxySQL is through its admin interface. This lends itself to online configuration (without having to restart the proxy) via SQL queries to its admin database. It's an effective way to configure it both manually and in an automated fashion.

As a secondary way to configure it, we have the configuration file.

Configuring ProxySQL through the admin interface

To log into the admin interface for MySQL (with the default credentials) use a mysql client and connect using the following admin credentials locally on port (6032):

$ mysql -u admin -padmin -h 127.0.0.1 -P6032 --prompt='Admin> '
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 4
Server version: 5.5.30 (ProxySQL Admin Module)

Copyright (c) 2000, 2016, 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>

note: If your MySQL client version is version 8.04 or higher add --default-auth=mysql_native_password to the above command to connect to the admin interface.

To log into the admin interface for PostgreSQL use the psql client and connect using admin on port 6132 (the Admin SQL commands are the same):

$ export PGPASSWORD=admin
$ psql -U admin -h 127.0.0.1 -p6132
psql (17.4 (Ubuntu 17.4-1.pgdg22.04+2), server 16.1)
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off, ALPN: none)
Type "help" for help.

admin=#

Once connected to the admin interface, you will have a list of databases and tables at your disposal that can be queried using the SQL language:

Admin> SHOW DATABASES;
+-----+---------+-------------------------------+
| seq | name    | file                          |
+-----+---------+-------------------------------+
| 0   | main    |                               |
| 2   | disk    | /var/lib/proxysql/proxysql.db |
| 3   | stats   |                               |
| 4   | monitor |                               |
+-----+---------+-------------------------------+
4 rows in set (0.00 sec)

This will allow you to control the list of the backend servers, how traffic is routed to them, and other important settings (such as caching, access control, etc). Once you've made modifications to the in-memory data structure, you must load the new configuration to the runtime, or persist the new settings to disk (so that they are still there after a restart of the proxy). A detailed tutorial on how to configure ProxySQL through the Admin interface is available here.

Configuring ProxySQL through the config file

Even though the config file should only be regarded as a secondary way to configure the proxy, we must not discard its value as a valid way to bootstrap a fresh ProxySQL install.

Let's quickly go over the main sections of the configuration file (this overview serves as a very high level overview of ProxySQL configuration).

Top-level sections:

  • admin_variables: contains global variables that control the functionality of the admin interface.

  • mysql_variables: contains global variables that control the functionality for handling the incoming MySQL traffic.

  • mysql_servers: contains rows for the mysql_servers table from the admin interface. Basically, these define the backend servers towards which the incoming MySQL traffic is routed. Rows are encoded as per the .cfg file format, here is an example:

    mysql_servers =
    (
    	{
    		address="127.0.0.1"
    		port=3306
    		hostgroup=0
    		max_connections=200
    	}
    )
    
  • mysql_users: contains rows for the mysql_users table from the admin interface. Basically, these define the users which can connect to the proxy, and the users with which the proxy can connect to the backend servers. Rows are encoded as per the .cfg file format, here is an example:

    mysql_users:
    (
    	{
    		username="root"
    		password="root"
    		default_hostgroup=0
    		max_connections=1000
    		default_schema="information_schema"
    		active=1
    	}
    )
    
  • mysql_query_rules: contains rows for the mysql_query_rules table from the admin interface. Basically, these define the rules used to classify and route the incoming MySQL traffic, according to various criteria (patterns matched, user used to run the query, etc.). Rows are encoded as per the .cfg file format, here is an example (Note: the example is a very generic query routing rule and it is recommended to create specific rules for queries rather than using a generic rule such as this):

    mysql_query_rules:
    (
    	{
    		rule_id=1
    		active=1
    		match_pattern="^SELECT .* FOR UPDATE$"
    		destination_hostgroup=0
    		apply=1
    	},
    	{
    		rule_id=2
    		active=1
    		match_pattern="^SELECT"
    		destination_hostgroup=1
    		apply=1
    	}
    )
    
  • pgsql_variables: contains global variables that control the functionality for handling the incoming PostgreSQL traffic.

  • pgsql_servers: contains rows for the pgsql_servers table from the admin interface. Basically, these define the backend servers towards which the incoming PostgreSQL traffic is routed. Rows are encoded as per the .cfg file format, here is an example:

    pgsql_servers =
    (
    	{
    		address="127.0.0.1"
    		port=5432
    		hostgroup=0
    		max_connections=200
    	}
    )
    
  • pgsql_users: contains rows for the pgsql_users table from the admin interface. Basically, these define the users which can connect to the proxy, and the users with which the proxy can connect to the backend servers. Rows are encoded as per the .cfg file format, here is an example:

    pgsql_users:
    (
    	{
    		username="postgres"
    		password="postgres"
    		default_hostgroup=0
    		max_connections=1000
    		active=1
    	}
    )
    
  • pgsql_query_rules: contains rows for the pgsql_query_rules table from the admin interface. Basically, these define the rules used to classify and route the incoming PostgreSQL traffic, according to various criteria (patterns matched, user used to run the query, etc.). Rows are encoded as per the .cfg file format, here is an example (Note: the example is a very generic query routing rule and it is recommended to create specific rules for queries rather than using a generic rule such as this):

    pgsql_query_rules:
    (
    	{
    		rule_id=1
    		active=1
    		match_pattern="^SELECT .* FOR UPDATE$"
    		destination_hostgroup=0
    		apply=1
    	},
    	{
    		rule_id=2
    		active=1
    		match_pattern="^SELECT"
    		destination_hostgroup=1
    		apply=1
    	}
    )
    
  • top-level configuration item: datadir, as a string, to point to the data dir.