0

I trying to add mysql data source on Grafana. My intention is create a Business KPI dashboard extracting leads and revenues from Mysql database.

This is the docker-compose.yml

version: '2'
services:

  # simple myself setup
  mysql:
    image: mysql:5.7
    ports:
      - "33060:3306"
    environment:
      MYSQL_ROOT_PASSWORD: myRootPassword123
      MYSQL_DATABASE: myDb
      MYSQL_USER: myDbUser
      MYSQL_PASSWORD: myPassword123

  # grafana used for graphing mysql data
  grafana:
    image: grafana/grafana
    links:
      - mysql
    ports:
      - '3000:3000'
    environment:
      GF_INSTALL_PLUGINS: percona-percona-app

And this is the containers up

952c95c5414b        grafana/grafana     "/run.sh"                26 minutes ago      Up 26 minutes       0.0.0.0:3000->3000/tcp               grafana_grafana_1
2cacddcebcf4        mysql:5.7           "docker-entrypoint.s…"   26 minutes ago      Up 26 minutes       33060/tcp, 0.0.0.0:33060->3306/tcp   grafana_mysql_1

When I go to grafana and try to configure a new MySQL data source, it always shows the TCP connection refused error.

I trying to connect using 127.0.0.1:33060 from inside of grafana dashboard.

Grafana configuration mysql data source

Thank you.

3
  • 1
    You are using an old version of docker-compose definition. You should upgrade to v>=3. Links are deprecated, you should use the v3 network definition instead. There is no need to map the mysql port to your host (unless you want to connect to it from your host of course). Localhost in docker means.... well localhost i.e. the current docker container. Grafana has no 33060 port opened on its own localhost. Once you have configured correctly, you can connect directly to mysql:3306 which will be handled automatically by docker compose based on the service name. Commented Nov 28, 2019 at 17:20
  • 1
    Networking in Compose is essential reading that describes the standard setup. Commented Nov 28, 2019 at 17:28
  • Thnaks for the info !! Commented Nov 29, 2019 at 8:43

1 Answer 1

4

Just to get you on track: the following will manage your services and create a default network for your compose project where all containers know each other using their services names.

Once up, Grafana will be available from your host on http://localhost:3000 and you can create a mysql datasource in using the address mysql:3306.

---
version: '3'
services:

  mysql:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: myRootPassword123
      MYSQL_DATABASE: myDb
      MYSQL_USER: myDbUser
      MYSQL_PASSWORD: myPassword123

  grafana:
    image: grafana/grafana
    ports:
      - '3000:3000'
    environment:
      GF_INSTALL_PLUGINS: percona-percona-app
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.