'mysqld_exporter doesn't connect to mariadb

I am running and mysqld_exporter on the same server. Since I have to use ansible to configure the exporter, I used cloud-alchemy ansible role based on the official prometheus mysqld_exporte that you can see here : https://github.com/cloudalchemy/ansible-mysqld_exporter.

I followed both the role and exporter requirements (ansible version, mysql user) and the installation runs well with no error. Yet according to the logs the exporter can not seem to connect to the database. Here is the error that I get :

caller=exporter.go:149 level=error msg="Error pinging mysqld" err="dial tcp 127.0.0.1:3306: connect: connection refused"

Here is my default/main.yaml looks like on the role :

---
mysqld_exporter_binary_local_dir: ""
mysqld_exporter_version: 0.14.0
mysqld_exporter_web_listen_address: "0.0.0.0:9104"

mysqld_exporter_dsn: "testexpo:xxxx@(localhost:3306)/"

mysqld_exporter_my_cnf: ""

mysqld_exporter_collect: []

mysqld_exporter_no_collect: []

The dsn has been changed according to the user configured. And by the way I can access my database with this user with the command line. All of the necessary ports are open and are listening.

I have tried to change the localhost part to 127.0.0.1, id did not work too.

I have no idea what to try anymore, so if you guys have any idea or advice I will gladly take them ! Thanks in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source