proxysql is a more powerful mysql proxy services to support dynamic adjustment mysql instance, rewrite the query, the query cache, monitoring, data mirroring, separate read and write
as well as ha, has recently released 2.0, it is worth at trial
Preparing the Environment
- docker-compose documents
version: "3"
services:
mysql:
image: mysql:5.7.16
ports:
- 3306:3306
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
environment:
MYSQL_ROOT_PASSWORD: dalongrong
MYSQL_DATABASE: test
MYSQL_USER: test
MYSQL_PASSWORD: test
TZ: Asia / Shanghai
proxysql:
image: proxysql/proxysql:2.0.5
volumes:
- "./proxysql.cnf:/etc/proxysql.cnf"
ports:
- "6033:6033"
- "6032:6032"
- proxysql.cnf file
Mainly some run proxysql about is configured, we can also configure the mysql server instance, the following, for a simple, straightforward manner using a configuration file
datadir="/var/lib/proxysql"
admin_variables=
{
admin_credentials="admin:admin;radmin:radmin"
mysql_ifaces="0.0.0.0:6032"
}
mysql_variables=
{
threads=4
max_connections=2048
default_query_delay=0
default_query_timeout=36000000
have_compress=true
poll_timeout=2000
interfaces="0.0.0.0:6033"
default_schema="information_schema"
stacksize=1048576
server_version="5.5.30"
connect_timeout_server=3000
monitor_username="root"
monitor_password="dalongrong"
monitor_history=600000
monitor_connect_interval=60000
monitor_ping_interval=10000
monitor_read_only_interval=1500
monitor_read_only_timeout=500
ping_interval_server_msec=120000
ping_timeout_server=500
commands_stats=true
sessions_sort=true
connect_retries_on_failure=10
}
mysql_servers =
(
{
address="mysql"
port=3306
hostgroup=0
max_connections=200
}
)
mysql_users:
(
{
username = "root"
password = "dalongrong"
default_hostgroup = 0
max_connections=1000
default_schema="information_schema"
active = 1
}
)
Start && simple operation
- start up
docker-compose up -d
- Management connection interface
mysql -h127.0.0.1 -P6032 -uradmin -pradmin --prompt "ProxySQL Admin>"
- Simple operation
show databases;
effect
ProxySQL Admin>show databases;
+-----+---------------+-------------------------------------+
| seq | name | file |
+-----+---------------+-------------------------------------+
| 0 | main | |
| 2 | disk | /var/lib/proxysql/proxysql.db |
| 3 | stats | |
| 4 | monitor | |
| 5 | stats_history | /var/lib/proxysql/proxysql_stats.db |
+-----+---------------+-------------------------------------+
5 rows in set (0.01 sec)
Query mysql server
select * from main.mysql_servers\G;
effect
select * from main.mysql_servers\G;
*************************** 1. row ***************************
hostgroup_id: 0
hostname: mysql
port: 3306
gtid_port: 0
status: ONLINE
weight: 1
compression: 0
max_connections: 200
max_replication_lag: 0
use_ssl: 0
max_latency_ms: 0
comment:
1 row in set (0.00 sec)
ERROR:
No query specified
Query mysql server runtime
select * from runtime_mysql_servers\G;
*************************** 1. row ***************************
hostgroup_id: 0
hostname: mysql
port: 3306
gtid_port: 0
status: ONLINE
weight: 1
compression: 0
max_connections: 200
max_replication_lag: 0
use_ssl: 0
max_latency_ms: 0
comment:
1 row in set (0.01 sec)
- Application connection
port for the 6033 application connection
Connection:
mysql -h127.0.0.1 -P6033 -uroot -pdalongrong
Simple Query
select * from rongdemo.usersinfo;
+----------+--------+
| username | userid |
+----------+--------+
| dalong | 1 |
+----------+--------+
1 row in set (0.00 sec)
Explanation
proxysql function is more powerful, performance is also very good, while providing for management, and connection address, mysql exposed to a standard protocol for the entry into force of the configured
not add mysql server instance to main.mysql_servers on it, you need to runtime
, at the same time also need to configure for persistence, there are associated command
LOAD MYSQL USERS TO RUNTIME;
SAVE MYSQL USERS TO DISK;
LOAD MYSQL SERVERS TO RUNTIME;
SAVE MYSQL SERVERS TO DISK;
LOAD MYSQL QUERY RULES TO RUNTIME;
SAVE MYSQL QUERY RULES TO DISK;
LOAD MYSQL VARIABLES TO RUNTIME;
SAVE MYSQL VARIABLES TO DISK;
LOAD ADMIN VARIABLES TO RUNTIME;
SAVE ADMIN VARIABLES TO DISK;
For proxysql, the community also provides many convenient monitoring tools, such as the exporter, convenient promethues integration with
the corresponding official documents dockerfile
FROM debian:stretch
MAINTAINER Nikolaos Vyzas <nick@proxysql.com>
RUN apt-get update && apt-get install -y wget lsb-release gnupg apt-transport-https ca-certificates && wget -O - 'https://repo.proxysql.com/ProxySQL/repo_pub_key' | apt-key add - && echo deb https://repo.proxysql.com/ProxySQL/proxysql-2.0.x/$(lsb_release -sc)/ ./ | tee /etc/apt/sources.list.d/proxysql.list && apt-get update && apt-get install proxysql=2.0.5 && rm -rf /var/lib/apt/lists/*
ENTRYPOINT ["proxysql", "-f", "-D", "/var/lib/proxysql"]
Reference material
https://github.com/sysown/proxysql/wiki/Configuring-ProxySQL
https://github.com/sysown/proxysql
https://github.com/rongfengliang/proxysql-docker-compose
https://hub.docker.com/r/proxysql/proxysql