Installation problems: Failed to ping DB

Summary

Cannot connect to the database during installation

Steps to reproduce

I am following instructions from the Installing Mattermost on Ubuntu 18.04 LTS manual. So far I have not received any error messages. I also tried troubleshooting with MySQL Installation Troubleshooting but every time I try to start the database I receive the same error. I have checked an re-checked the config.json file and entered the data exactly as instructed.

I am entering cd /opt/mattermost
and
sudo -u mattermost ./bin/mattermost

Expected behavior

The server is supposed to start.

Observed behavior

{“level”:“info”,“ts”:1605258928.8680353,“caller”:“utils/i18n.go:90”,“msg”:“Loaded system translations”,“for locale”:“en”,“from locale”:"/opt/mattermost/i18n/en.json"}
{“level”:“info”,“ts”:1605258928.8791585,“caller”:“sqlstore/supplier.go:232”,“msg”:“Pinging SQL”,“database”:“master”}
{“level”:“error”,“ts”:1605258928.8796403,“caller”:“sqlstore/supplier.go:244”,“msg”:“Failed to ping DB”,“error”:“dial tcp 81.169.228.59:3306: connect: connection refused”,“retrying in seconds”:10}
{“level”:“info”,“ts”:1605258938.8797626,“caller”:“sqlstore/supplier.go:232”,“msg”:“Pinging SQL”,“database”:“master”}
{“level”:“error”,“ts”:1605258938.8801558,“caller”:“sqlstore/supplier.go:244”,“msg”:“Failed to ping DB”,“error”:“dial tcp 81.169.228.59:3306: connect: connection refused”,“retrying in seconds”:10}

Any way I have tried to start the server did not work. Restarting it also did not work and leads to the same error message. What am I missing?

Hello @AgileParent, I’m sorry to hear that you’re having issues. Are you connecting to a local database or a remotely hosted database?

I ran a Nmap (network mapper) scan on the IP address you included in your original post (see quote)

and determined that it is not possible for you to connect to a database instance on this address, as the port 3306 (the common MySQL port, and the one that is utilized in this error message) is not open, as you can see in the following scan output, in which the port doesn’t even show up on the results, indicating that the port is completely closed and unable to be accessed from outside the local environment of the server.

Host is up (0.16s latency).
Not shown: 3392 closed ports
PORT    STATE    SERVICE
22/tcp  open     ssh
25/tcp  filtered smtp
80/tcp  open     http
137/tcp filtered netbios-ns
138/tcp filtered netbios-dgm
139/tcp filtered netbios-ssn
443/tcp open     https
646/tcp filtered ldp

Nmap done: 1 IP address (1 host up) scanned in 30.88 seconds

However, if the database that you are trying to connect to is on the same local server as your Mattermost instance, I suggest changing the IP address to 127.0.0.1 as this is the standard loopback interface for all networked devices–this will tell Mattermost to connect to the local server on port 3306 and therefore connect to the local database.

2 Likes

Thank you, this worked.

1 Like

I’m very glad to hear that, your welcome! :slight_smile:

Hello all!

I’m having the same error message within a Docker setup: a local MySQL instance inside a separate docker container and another one from the mattermost/mattermost-team-edition image. These are my env vars in my docker-compose.yml:

DB_HOST: mysql-1
DB_PORT_NUMBER: '35374'
MM_DBNAME: mat
MM_PASSWORD: ****
MM_SQLSETTINGS_DATASOURCE: ***:****@tcp(mysql-1:35374)/mat?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s
MM_SQLSETTINGS_DRIVERNAME: mysql
MM_USERNAME: ***

The full error is:
{“level”:“error”,“ts”:1606734568.468897,“caller”:“sqlstore/supplier.go:247”,“msg”:“Failed to ping DB”,“error”:“dial tcp 172.18.0.2:35374: connect: connection refused”,“retrying in seconds”:10}

The hostname mysql-1 is translated to the correct ip 172.18.0.2 and both containers are on the same Docker network. I can also manually login into MySQL with the user and password using docker exec. Other apps on the same docker network are also using this MySQL instance…

Does someone see what I’m missing?

Would you be willing to provide the section of your Mattermost config.json file where you have your database configuration (with redactions to protect information as needed, of course) so that we can see that it lines up properly?

Also, have you made sure that your MySQL database is running as a daemon, and not just when you connect to the console prompt?

1 Like

Hi, yes, here is the SqlSettings part of my config.json. MySQL is running OK (I have both a Nextcloud and a Matomo instance using it).
Is there a way to start Mattermost in a debug or verbose mode? Maybe that will give more info about MySQL’s “connection refused” message (assuming it is from there)?

"SqlSettings": {
    "DriverName": "mysql",
    "DataSource": "***:***@tcp(mysql-1:35374)/mat?charset=utf8mb4,utf8\u0026readTimeout=30s\u0026writeTimeout=30s",
    "DataSourceReplicas": [],
    "DataSourceSearchReplicas": [],
    "MaxIdleConns": 20,
    "ConnMaxLifetimeMilliseconds": 3600000,
    "MaxOpenConns": 300,
    "Trace": false,
    "AtRestEncryptKey": "***",
    "QueryTimeout": 30,
    "DisableDatabaseSearch": false
},

This is my docker-compose.yml too:

networks:
  proxy:
	external:
	  name: ${DOCKER_NETWORK}

services:
  mattermost:
	image: mattermost/mattermost-team-edition
	container_name: mattermost
	restart: always
	environment:
	  DB_HOST: ${DB_HOST}
	  DB_PORT_NUMBER: ${DB_PORT}
	  MM_DBNAME: ${DB_NAME}
	  MM_USERNAME: ${DB_USER}
	  MM_PASSWORD: ${DB_PASS}
	  MM_SQLSETTINGS_DATASOURCE: '${DB_USER}:${DB_PASS}@tcp(${DB_HOST}:${DB_PORT})/${DB_NAME}?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s'
	  MM_SQLSETTINGS_DRIVERNAME: 'mysql'
	networks:
	  - proxy
	volumes:
	  - ./app/config:/mattermost/config:rw
	  - ./app/data:/mattermost/data:rw
	  - ./app/logs:/mattermost/logs:rw
	  - ./app/plugins:/mattermost/plugins:rw
	  - /etc/localtime:/etc/localtime:ro
	labels:
	  traefik.enable: 'true'
	  traefik.backend: 'mattermost'
	  traefik.docker.network: '${DOCKER_NETWORK}'
	  traefik.frontend.rule: 'Host:${DOMAIN}'
	  traefik.passHostHeader: 'true'
	  traefik.frontend.headers.SSLRedirect: 'true'

Yes there is, either in your config.json file or from the mattermost web interface you can change the logging level from info or errors, to DEBUG and this will enable debug logging!

Hello @XxLilBoPeepsxX, it took some time but I tried with FileLevel to “DEBUG”, but the logs/mattermost.log does not give any extra information… Even with the log level is gives the exact same reporting concerning the “connection refused” error:

{"level":"info","ts":1609000235.9435613,"caller":"sqlstore/supplier.go:235","msg":"Pinging SQL","database":"master"}
{"level":"error","ts":1609000235.9461305,"caller":"sqlstore/supplier.go:247","msg":"Failed to ping DB","error":"dial tcp 172.18.0.2:35374: connect: connection refused","retrying in seconds":10}

I continue my investigation, but if you know another trick to debug this, let me know!

Could you verify that your MySQL server is allowing connections on the port your using and that there are enough resources allocated to actually process the requests?

I ran into the similar issue
Connection string:

"DataSource": "mmuser:mmPassword@tcp(localhost:3306)/mattermost?charset=utf8mb4,utf8\u0026readTimeout=30s\u0026writeTimeout=30s"

I was getting below error on command sudo -u mattermost ./bin/mattermost

Solution:
MySql was running on a different port on my system, it was running on port 6606 and not on 3306.

You can run the below commands to check the MySql port

cd /etc/mysql/mysql.conf.d
sudo nano mysqld.cnf

in the file mysqld.cnf you can look at the value for port

Correct connection string that worked for me then

"DataSource": "mmuser:mmPassword@tcp(localhost:6606)/mattermost?charset=utf8mb4,utf8\u0026readTimeout=30s\u0026writeTimeout=30s"