Giter Club home page Giter Club logo

proxysql's Introduction

CI-selftests CI-repltests CodeQL Package-Build

ProxySQL

Introduction

ProxySQL is a high performance, high availability, protocol aware proxy for MySQL and forks (like Percona Server and MariaDB). 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/v2.4.2/proxysql_2.4.2-ubuntu20_amd64.deb
dpkg -i proxysql_2.4.2-ubuntu20_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-2.4.x-keyring.gpg 'https://repo.proxysql.com/ProxySQL/proxysql-2.4.x/repo_pub_key.gpg'
echo "deb https://repo.proxysql.com/ProxySQL/proxysql-2.4.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-2.4.x/centos/\$releasever
gpgcheck=1
gpgkey=https://repo.proxysql.com/ProxySQL/proxysql-2.4.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-2.4.x/centos/8
gpgcheck=1
gpgkey=https://repo.proxysql.com/ProxySQL/proxysql-2.4.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-2.4.x/almalinux/\$releasever
gpgcheck=1
gpgkey=https://repo.proxysql.com/ProxySQL/proxysql-2.4.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-2.4.x/opensuse/\$releasever_major
gpgcheck=1
EOF

or

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

Installing:

yum install proxysql OR yum install proxysql-version

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 -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

Restarting ProxySQL:

service proxysql restart

Or alternatively via the Admin interface:

$ 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

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/v2.1.0/proxysql_2.1.0-ubuntu16_amd64.deb
dpkg -i proxysql_2.1.0-ubuntu16_amd64.deb
service proxysql restart

How to check the ProxySQL version

$ proxysql --version
ProxySQL version 2.1.0-544-g17a4b4a7, 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
Main init phase0 completed in 0.000146 secs.
ProxySQL version 2.1.0-544-g17a4b4a7_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 (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.

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
     	}
     )
  • top-level configuration item: datadir, as a string, to point to the data dir.

proxysql's People

Contributors

alexjurkiewicz avatar alpes214 avatar aminet avatar anphucbui avatar bibstha avatar bpmdoty avatar bskllzh avatar carsonip avatar csoulios avatar dieken avatar dveeden avatar everpcpc avatar hugmeir avatar iprunache avatar jaredev avatar javierjf avatar javsanpar avatar jesmarcannao avatar kirs avatar krzysztof-ksiazek avatar minichate avatar mirostauder avatar pondix avatar rahim-kanji avatar renecannao avatar satori avatar saunderst avatar ton31337 avatar wjordan avatar yiyao-ms avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

proxysql's Issues

Write a cleanup function for per-thread MySQL_Connection_Pool

Periodically, a cleanup function should be called in the per-thread MySQL_Connection_Pool instance to clean up all the expired connections.

To note that in this context "expired" means that have been in the per-thread instance for too long and that now they need to be moved into the shared instance

Handle error 1044 and error 1049

This is related to #45 .
If a client issue INIT_DB this is always successful.
Although, when a client run a query and INIT_DB is sent to the database server that can answer with OK or ERR for:

  • 1044 : Access denied
  • 1049 : Unknown database
    These errors must be returned to the application (probably just as error 1044) and server_userinfo.schemaname needs to be rolled back.

An alternative approach (that should be configurable) is to terminate the session as soon as such errors arise.

These errors can be logged: optionally, configurable

Create a per-thread variable that store current time

Many threads need to know the current time with a good precision, although calling time functions every time is needed is time consuming.
Each thread could have its own per-thread variable to store current time, updated within the thread when required, and accessible to all the functions.

Configurable target for debug logging (DEBUG only)

Currently debug logging goes only to stderr.
This should be enhanced in a way that logging can go to either stderr (like now) or sent to an internal queue where debug entries can be:
a) written on a log file
b) sent to SQLite3
c) both a and b

Prioritize the execution of the Admin module

The Admin module should start before any other module.
Should be possible to hold the execution of other modules unless they are explicitly started from the admin interface.
Should be even possible to restart other modules without restarting the process.

Define new expire variables for MySQL_Connection_Pool

Two variables need to define the time to lives of a connection:

  • in the per-thread connection pool before being moved into the shared connection pool
  • in the shared connection pool before being purged

These need to be defined globally and configurable at runtime.

Implement or remove support for domains

See issue #9 for a description of what domains are.
Support for domains needs to be implemented in multiple modules.
Maybe is more appropriate to run multiple instances of ProxySQL (one per domain) instead of having one instance processing all domains

Trace session variables

Most of the session variables need to be traced, so if a client specifically set them actions can be taken.
Ex:

  • start transaction;
  • change timeout;
  • disable qc
  • change charset

Would be more interesting if all the variables are kept local

Write a cleanup function for shared MySQL_Connection_Pool

Periodically, a cleanup function should be called in the shared MySQL_Connection_Pool instance to clean up all the expired connections.

To note that in this context "expired" means that have been in the shared instance for too long and that they need to be closed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.