# \[Solved\] Initial setup problems with connection to database

**URL:** <https://forum.mattermost.com/t/solved-initial-setup-problems-with-connection-to-database/484>\
**Category:** Troubleshooting\
**Created:** [November 4, 2015, 9:24pm UTC](https://forum.mattermost.com/t/solved-initial-setup-problems-with-connection-to-database/484 "2015-11-04T21:24:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Slimmons](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@Slimmons](https://forum.mattermost.com/u/Slimmons)\
**Post date:** [November 4, 2015, 9:24pm UTC](https://forum.mattermost.com/t/solved-initial-setup-problems-with-connection-to-database/484/1 "2015-11-04T21:24:31Z")

</div>

I’m following the instructions [here](https://github.com/mattermost/platform/blob/release-1.0.0/doc/install/prod-ubuntu.md). I’m on ubuntu 14.04 server, and it was a fresh install with nothing on it.

When I got to step 8 under “Setup Mattermost Server” and run `./platform` I get an error:

```auto
[CRIT] Failed to ping db err:dial tcp 192.168.1.2:5432: connection refused
panic: Failed to open sql connection dial tcp 192.168.1.2:5432: connection refused

goroutine 1 [running]:
github.com/mattermost/platform/store.setupConnection(0xb4ddf0, 0x6, 0xc20800bc88, 0x8, 0xc208054120, 0x5d, 0xa, 0xa, 0x4e0500, 0x95d960)
    /home/travis/gopath/src/github.com/mattermost/platform/store/sql_store.go:146 +0x581
github.com/mattermost/platform/store.NewSqlStore(0x0, 0x0)
    /home/travis/gopath/src/github.com/mattermost/platform/store/sql_store.go:52 +0x106
github.com/mattermost/platform/api.NewServer()
    /home/travis/gopath/src/github.com/mattermost/platform/api/server.go:33 +0x15a
main.main()
    /home/travis/gopath/src/github.com/mattermost/platform/mattermost.go:55 +0x4d8

goroutine 6 [syscall]:
os/signal.loop()
    /usr/local/go/src/os/signal/signal_unix.go:21 +0x1f
created by os/signal.init·1
    /usr/local/go/src/os/signal/signal_unix.go:27 +0x35

goroutine 7 [chan receive]:
code.google.com/p/log4go.ConsoleLogWriter.run(0xc208054240, 0x7f4746a23ff0, 0xc20802c008)
    /home/travis/gopath/src/github.com/mattermost/platform/Godeps/_workspace/src/code.google.com/p/log4go/termlog.go:27 +0x7a
created by code.google.com/p/log4go.NewConsoleLogWriter
    /home/travis/gopath/src/github.com/mattermost/platform/Godeps/_workspace/src/code.google.com/p/log4go/termlog.go:19 +0x6b

goroutine 8 [select]:
code.google.com/p/log4go.func·002()
    /home/travis/gopath/src/github.com/mattermost/platform/Godeps/_workspace/src/code.google.com/p/log4go/filelog.go:84 +0xa53
created by code.google.com/p/log4go.NewFileLogWriter
    /home/travis/gopath/src/github.com/mattermost/platform/Godeps/_workspace/src/code.google.com/p/log4go/filelog.go:116 +0x3da

goroutine 9 [chan receive]:
database/sql.(*DB).connectionOpener(0xc20803d540)
    /usr/local/go/src/database/sql/sql.go:589 +0x4c
created by database/sql.Open
    /usr/local/go/src/database/sql/sql.go:452 +0x31c

```

This problem is almost identical to [this](http://forum.mattermost.com/t/solved-failed-to-ping-db-err/441) one, but they just say they were able to fix that first problem, and never said how.

my 5432 port is open;

**sudo netstat -tulpn**

```auto
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 922/sshd        
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 1028/postgres   
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1121/nginx      
tcp6 0 0 :::22 :::* LISTEN 922/sshd        
tcp6 0 0 ::1:5432 :::* LISTEN 1028/postgres   

```

Any ideas?

---

<div class="post-metadata">

**Author:** ![coreyhulen](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/coreyhulen/32/25_2.png) [@coreyhulen](https://forum.mattermost.com/u/coreyhulen)\
**Post date:** [November 4, 2015, 9:52pm UTC](https://forum.mattermost.com/t/solved-initial-setup-problems-with-connection-to-database/484/2 "2015-11-04T21:52:08Z")

</div>

Is the db on a different box? can you connect via the `psql` command?

maybe something like [http://www.thegeekstuff.com/2014/02/enable-remote-postgresql-connection/](http://www.thegeekstuff.com/2014/02/enable-remote-postgresql-connection/)

---

<div class="post-metadata">

**Author:** ![Slimmons](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@Slimmons](https://forum.mattermost.com/u/Slimmons)\
**Post date:** [November 4, 2015, 9:57pm UTC](https://forum.mattermost.com/t/solved-initial-setup-problems-with-connection-to-database/484/3 "2015-11-04T21:57:30Z")

</div>

Hi, thanks for the response. I’m setting up Mattermost all on a single machine, including the db. From the [instructions](https://github.com/mattermost/platform/blob/release-1.0.0/doc/install/prod-ubuntu.md), I set up a postgres user on my machine, and I am able to run `psql` and connect and view the database.

I am a postgres noob, so I’ll link my pg\_hba.conf just to make sure I don’t have something obviously wrong there.

```auto
# Database administrative login by Unix domain socket
local all postgres peer

# TYPE DATABASE USER ADDRESS METHOD

# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5

```

---

<div class="post-metadata">

**Author:** ![coreyhulen](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/coreyhulen/32/25_2.png) [@coreyhulen](https://forum.mattermost.com/u/coreyhulen)\
**Post date:** [November 4, 2015, 10:04pm UTC](https://forum.mattermost.com/t/solved-initial-setup-problems-with-connection-to-database/484/4 "2015-11-04T22:04:06Z")

</div>

Can you past in the db connection string in config.json minus the username/pwd ? It looks like it’s trying to connect to 192.168.1.2. I think you can probably have 127.0.0.1 instead. What psql cmd did you run?

---

<div class="post-metadata">

**Author:** ![Slimmons](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@Slimmons](https://forum.mattermost.com/u/Slimmons)\
**Post date:** [November 4, 2015, 10:09pm UTC](https://forum.mattermost.com/t/solved-initial-setup-problems-with-connection-to-database/484/5 "2015-11-04T22:09:46Z")

</div>

Well that was simple enough. I appreciate the help. If I change it to 127.0.0.1 it works fine. I tried that earlier, but I think I tried it when I had another setting incorrect. Thanks again!

---

<div class="post-metadata">

**Author:** ![avas27JTG](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/avas27jtg/32/5456_2.png) [@avas27JTG](https://forum.mattermost.com/u/avas27JTG)\
**Post date:** [April 13, 2022, 4:55pm UTC](https://forum.mattermost.com/t/solved-initial-setup-problems-with-connection-to-database/484/6 "2022-04-13T16:55:07Z")

</div>

I ran into the similar issue  
Connection string:

```auto
"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`

 ![image](https://us1.discourse-cdn.com/flex020/uploads/mattermost/original/2X/8/8860703fb5a816b13d5f2065df3da639b5de8308.png)

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

```auto
cd /etc/mysql/mysql.conf.d

```

```auto
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

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

```
