0

I want to connect redash to MySQL Server. I added MYSQL_TCP_PORT for server to use TCP connection, not default UNIX socket (to avoid mysqld.sock error). If I go to mysql container and mysql -p - I can open mysql shell. But If I test connection in redash - it will return (2006, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)").

Connection test failed

enter image description here

Here is my docker-compose file:

# This configuration file is for the **development** setup.
# For a production example please refer to getredash/setup repository on GitHub.
version: "2.2"
x-redash-service: &redash-service
  build:
    context: .
    # args:
    #   skip_frontend_build: "true"  # set to empty string to build
  volumes:
    - .:/app
  env_file:
    - .env
x-redash-environment: &redash-environment
  REDASH_LOG_LEVEL: "INFO"
  REDASH_REDIS_URL: "redis://redis:6379/0"
  REDASH_DATABASE_URL: "postgresql://postgres@postgres/postgres"
  REDASH_RATELIMIT_ENABLED: "false"
  REDASH_MAIL_DEFAULT_SENDER: "redash@example.com"
  REDASH_MAIL_SERVER: "email"
  REDASH_ENFORCE_CSRF: "true"
  REDASH_GUNICORN_TIMEOUT: 60
  # Set secret keys in the .env file
services:
  server:
    <<: *redash-service
    command: dev_server
    depends_on:
      - postgres
      - redis
    ports:
      - "5000:5000"
      - "5678:5678"
    networks:
      - default_network
    environment:
      <<: *redash-environment
      PYTHONUNBUFFERED: 0
  scheduler:
    <<: *redash-service
    command: dev_scheduler
    depends_on:
      - server
    networks:
      - default_network
    environment:
      <<: *redash-environment
  worker:
    <<: *redash-service
    command: dev_worker
    depends_on:
      - server
    networks:
      - default_network
    environment:
      <<: *redash-environment
      PYTHONUNBUFFERED: 0
  redis:
    image: redis:3-alpine
    restart: unless-stopped
    networks:
      - default_network
  postgres:
    image: postgres:9.5-alpine
    # The following turns the DB into less durable, but gains significant performance improvements for the tests run (x3
    # improvement on my personal machine). We should consider moving this into a dedicated Docker Compose configuration for
    # tests.
    ports:
      - "15432:5432"
    command: "postgres -c fsync=off -c full_page_writes=off -c synchronous_commit=OFF"
    restart: unless-stopped
    networks:
      - default_network
    environment:
      POSTGRES_HOST_AUTH_METHOD: "trust"
  email:
    image: djfarrelly/maildev
    ports:
      - "1080:80"
    restart: unless-stopped
    networks:
      - default_network
  mysql:
    image: mysql/mysql-server:latest
    ports:
      - "3306:3306"
    restart: unless-stopped
    container_name: mysql
    networks:
      - default_network
    environment:
      MYSQL_ROOT_PASSWORD: "${MYSQL_ROOT_PASSWORD}"
      MYSQL_TCP_PORT: 3306

networks:
  default_network:
    external: false
    name: default_network
    driver: bridge

As I see - redash is connecting via unix socket - not TCP connection (otherwise there will no mysqld.sock err). I don't know - what I should fix in docker-compose or somewhere else to make it connect properly. Any suggestions? If you need me to provide more info - ask me please

Shadow
  • 33,525
  • 10
  • 51
  • 64
Alexey
  • 185
  • 12
  • You should be using `mysql`, not `localhost`. – user1191247 Feb 16 '23 at 21:41
  • @nnichols maybe worked (changed `localhost` to `mysql`, but it says I cannot connect via current ip, probably I should specify ip in network), I will reply a little later – Alexey Feb 17 '23 at 05:20
  • @nnichols worked, but could you please explain why should I use mysql, not localhost or 127.0.0.1 as I usually do? What is mysql in this case? – Alexey Feb 17 '23 at 19:21
  • The MySQL service is not running in the same container as redash so there is no MySQL instance to connect to on the local loopback address. `mysql` is the name you gave to the service in your docker-compose. Just as you are using `redis` and `postgres` to address their respective containers in the `x-redash-environment` config. – user1191247 Feb 17 '23 at 19:33

0 Answers0