Docker compose mysql_exporter start error

docker-compse.yml

version: '3'
services:
    prometheus:
        image: prom/prometheus:latest
        volumes:
            - ./prometheus.yml:/etc/prometheus/prometheus.yml
            - /etc/localtime:/etc/localtime:ro
        ports:
            - "9091:9090"
        networks:
            - "net"
        depends_on:
            - mysql
        links:
            - mysql:mysql
    grafana:
        image: grafana/grafana:latest
        volumes:
            - /etc/localtime:/etc/localtime:ro
        ports:
            - "3001:3000"
        networks:
            - "net"
        depends_on:
            - prometheus
        links:
            - prometheus:prometheus
    mysql:
        image: prom/mysqld-exporter:latest
        volumes:
            - /etc/localtime:/etc/localtime:ro
        environment:
            DATA_SOURCE_NAME: "mysql_monitor:123@(192.168.50.11:3306)/"
        networks:
            - "net"

networks:
    net:

prometheus.yml

global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['localhost:9090']

  - job_name: 'mysql'
    static_configs:
    - targets: ['mysql:9104']

mysqld-exporter logs

prometheus-mysql-1       | ts=2023-06-30T13:44:35.523Z caller=mysqld_exporter.go:220 level=info msg="Starting mysqld_exporter" version="(version=0.15.0, branch=HEAD, revision=6ca2a42f97f3403c7788ff4f374430aa267a6b6b)"
prometheus-mysql-1       | ts=2023-06-30T13:44:35.523Z caller=mysqld_exporter.go:221 level=info msg="Build context" build_context="(go=go1.20.5, platform=linux/amd64, user=root@c4fca471a5b1, date=20230624-04:09:04, tags=netgo)"
prometheus-mysql-1       | ts=2023-06-30T13:44:35.523Z caller=config.go:150 level=error msg="failed to validate config" section=client err="no user specified in section or parent"
prometheus-mysql-1       | ts=2023-06-30T13:44:35.523Z caller=mysqld_exporter.go:225 level=info msg="Error parsing host config" file=.my.cnf err="no configuration found"
prometheus-mysql-1 exited with code 1

i can connect mysql via mysql_monitor:123@(192.168.50.11:3306)/ so username passwd ip port was correct
please help ~

I faced the same problem today, it seems like the docs are a little bit outdated, i was able to make it work with this docker compose file:

  mysqld-exporter:
    image: quay.io/prometheus/mysqld-exporter
    container_name: mysqld-exporter
    restart: unless-stopped
    command:
     - "--mysqld.username=user:password"
     - "--mysqld.address=host:port"
    networks:
      - mynet	
3 Likes

Thank you for this

I had the same issue and @PouriaMzn solution works for me