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.
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…
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?
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)?
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?