0

I am looking to setup proxysql and mysql locally with Docker so I can stream all outgoing logs (including any failed logs) with something like

docker logs -f proxysql

This is so I can debug queries etc. I have made good progress. My docker compose file looks like this

services:
  db:
    image: mysql
    command: --default-authentication-plugin=mysql_native_password
    container_name: mysql
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_USER: dbuser
      MYSQL_PASSWORD: password
    ports:
      - 33060:33060
      - 3306:3306
  proxysql:
    build:
       context: ./proxysql
    image: ubuntu
    container_name: proxysql
    command: tail -F anything
    ports:
      - 6032:6032
    depends_on:
      - db

My sqlproxy Dockerfile looks like this

FROM ubuntu:18.04

RUN \
  apt-get -y update && \
  apt-get -y install mysql-client wget gdebi && \ 
  wget https://github.com/sysown/proxysql/releases/download/v2.0.2/proxysql_2.0.2-ubuntu18_amd64.deb && \
  gdebi -n proxysql_2.0.2-ubuntu18_amd64.deb

So I can ssh into the proxysql container and I can verify that I can connect to the db container from inside the proxysql container.

by running this command. Notice that db is the name of the mysql container

mysql -uroot -hdb -ppassword

I can bring up a proxysql by running the following command

proxysql -f

Right with that out of the way down to my question.


1) How to I connect to the database via the proxy from my local machine? My thoughts are its something like?

mysql -uadmin -padmin -h127.0.0.1 -P6032

2) How do I configure the sqlproxy on the proxysql container? I have taken a look at the default /etc/proxysql.cnf files and this is where im a bit confused? I have copied the config here with what I think the values should be?

admin_variables=
{
    admin_credentials="admin:admin"
    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;/tmp/proxysql.sock"
    interfaces="0.0.0.0:6033"
    default_schema="information_schema"
    stacksize=1048576
    server_version="5.5.30"
    connect_timeout_server=3000
# make sure to configure monitor username and password
# https://github.com/sysown/proxysql/wiki/Global-variables#mysql-monitor_username-mysql-monitor_password
    monitor_username="monitor"
    monitor_password="monitor"
    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
}


# defines all the MySQL servers
mysql_servers =
(
    {
        address = "db" # no default, required . If port is 0 , address is interpred as a Unix Socket Domain
        port = 3306           # no default, required . If port is 0 , address is interpred as a Unix Socket Domain
#       hostgroup = 0           # no default, required
#       status = "ONLINE"     # default: ONLINE
#       weight = 1            # default: 1
#       compression = 0       # default: 0
#   max_replication_lag = 10  # default 0 . If greater than 0 and replication lag passes such threshold, the server is shunned
    }
)


# defines all the MySQL users
mysql_users:
(
    {
        username = "root" # no default , required
        password = "password" # default: ''
        default_hostgroup = 0 # default: 0
        active = 1            # default: 1
    }
)


#defines MySQL Query Rules
mysql_query_rules:
(
)

scheduler=
(
#  {
#    id=1
#    active=0
#    interval_ms=10000
#    filename="/var/lib/proxysql/proxysql_galera_checker.sh"
#    arg1="0"
#    arg2="0"
#    arg3="0"
#    arg4="1"
#    arg5="/var/lib/proxysql/proxysql_galera_checker.log"
#  }
)


mysql_replication_hostgroups=
(
#        {
#                writer_hostgroup=30
#                reader_hostgroup=40
#                comment="test repl 1"
#       },
#       {
#                writer_hostgroup=50
#                reader_hostgroup=60
#                comment="test repl 2"
#        }
)
Robbo_UK
  • 11,351
  • 25
  • 81
  • 117

1 Answers1

0

There's a container created by someone here -> https://github.com/Plopix/docker-mysqlproxyprofiler. What this container does is proxies all your requests to your existing database container, and logs a debug of all the queries using a .lua script from https://github.com/patrickallaert/MySQL-Proxy-scripts-for-devs. Hope this helps.

Mieghi
  • 26
  • 1
  • 1
  • 3
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. [Read this](https://stackoverflow.com/help/how-to-answer). – Shanteshwar Inde May 13 '19 at 11:42