question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failing to connect graphql_engine to my mySQL container

See original GitHub issue

Hey folks, I have the following Docker container running :

version: "3.7"
services:
    db:
        image: mysql:8.0.14
        command: --default-authentication-plugin=mysql_native_password
        restart: always
        volumes:
            - "./data:/var/lib/mysql:rw"
        ports:
            - 3306:3306
        environment:
            - MYSQL_ROOT_PASSWORD=root
    phpmyadmin:
        image: phpmyadmin
        restart: always
        ports:
            - 9090:80
        environment:
            - PMA_ARBITRARY=1
            - UPLOAD_LIMIT=3000000000

Using the example from the docs I’m trying to launch a graphql_engine container to connect to my mySQL container so I have the following :

version: "3.6"
services:
    postgres:
        image: postgres:12
        restart: always
        volumes:
            - db_data:/var/lib/postgresql/data
        environment:
            POSTGRES_PASSWORD: postgrespassword
    graphql-engine:
        image: hasura/graphql-engine:pull5655-633f084f
        ports:
            - "8080:8080"
        depends_on:
            - "postgres"
        command:
            - graphql-engine
            - --mysql-host
            - "127.0.0.1"
            - --mysql-user
            - "admin"
            - --mysql-port
            - "3306"
            - --mysql-dbname
            - "db_test"
            - --mysql-password
            - "admin"
            - serve
        restart: always
        environment:
            HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:postgrespassword@postgres:5432/postgres
            ## enable the console served by server
            HASURA_GRAPHQL_ENABLE_CONSOLE: "true" # set to "false" to disable console
            ## enable debugging mode. It is recommended to disable this in production
            HASURA_GRAPHQL_DEV_MODE: "true"
            HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
            ## uncomment next line to set an admin secret
            # HASURA_GRAPHQL_ADMIN_SECRET: myadminsecretkey
volumes:
    db_data:

I assume I’m not using the expected --mysql-host value here since I only get errors about the container not being able to connect to mysql.

If I use '127.0.0.1' or localhost I get a Can't connect to local MySQL server through socket error

My mySQL container is available on my host-machine localhost:3306 though via a SQL client.

Any pointers would be greatly appreciated 😄 Thanks!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8

github_iconTop GitHub Comments

2reactions
thomasfallercommented, Sep 14, 2020

Nervermind, sorted it, thanks

1reaction
benmartecommented, Feb 24, 2021

I’m also running into this issue what’s interesting is the different error messages based on which host I use.

If I use 127.0.0.1 or my actual IP address 192.168.2.191 I get this error:

graphql-engine_1  | {"type":"startup","timestamp":"2021-02-16T14:18:13.714+0000","level":"info","detail":{"kind":"server_configuration","info":{"live_query_options":{"batch_size":100,"refetch_delay":1},"transaction_isolation":"ISOLATION LEVEL READ COMMITTED","plan_cache_options":{"plan_cache_size":4000},"enabled_log_types":["http-log","websocket-log","startup","webhook-log","query-log"],"server_host":"HostAny","enable_allowlist":false,"log_level":"info","auth_hook_mode":null,"use_prepared_statements":true,"unauth_role":null,"stringify_numeric_types":false,"enabled_apis":["metadata","graphql","config","pgdump","developer"],"enable_telemetry":true,"enable_console":true,"auth_hook":null,"jwt_secret":null,"cors_config":{"allowed_origins":"*","disabled":false,"ws_read_cookie":null},"console_assets_dir":null,"admin_secret_set":false,"port":8080}}}
graphql-engine_1  | {"type":"startup","timestamp":"2021-02-16T14:18:13.714+0000","level":"info","detail":{"kind":"postgres_connection","info":{"retries":1,"database_url":"postgres://postgres:...@postgres:5432/postgres"}}}
graphql-engine_1  | {"type":"pg-client","timestamp":"2021-02-16T14:18:19.116+0000","level":"warn","detail":{"message":"postgres connection failed, retrying(0)."}}
graphql-engine_1  | {"type":"pg-client","timestamp":"2021-02-16T14:18:24.562+0000","level":"warn","detail":{"message":"postgres connection failed, retrying(1)."}}
graphql-engine_1  | {"type":"startup","timestamp":"2021-02-16T14:18:24.562+0000","level":"error","detail":{"kind":"catalog_migrate","info":{"internal":"could not translate host name \"postgres\" to address: Name or service not known\n","path":"$","error":"connection error","code":"postgres-error"}}}graphql-engine_1  | Connected to MySQL!
graphql-engine_1  | {"internal":"could not translate host name \"postgres\" to address: Name or service not known\n","path":"$","error":"connection error","code":"postgres-error"}

If I use localhost I get this one:

graphql-engine_1  | graphql-engine: ConnectionError {errFunction = "connect", errNumber = 2002, errMessage = "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)"}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does my docker mysql database container refuse ...
To connect, you have to use the service name declared in your docker-compose.yml instead of container name.
Read more >
MySQL preview | Hasura GraphQL Docs
Step 3: Run Hasura GraphQL engine​. The following command will run Hasura along with a Postgres database required for its functioning. $ docker...
Read more >
Hasura Console error: [...] No connection could be made ...
I believe the reason might be that the graphql-engine wasn't running. Try this: Run hasura init; In the root directory create docker-compose.yaml file...
Read more >
Unable to connect to MySQL server (Docker)
I have set up a Docker container with a MySQL server running version 8.0.21 (also tried 8.0). Whenever I try to connect to...
Read more >
Cricket database schema - Seba Online
of editing this file, please use the migrations feature of Cricket Match ... Students and Projects Lovers can Download Projects with MySQL Database...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found