Database setting is not correct: dial tcp 127.0.0.1:3306: getsockopt: connection refused


#1

Infos:

Gogs version: 0.11.28.0718
Operating system: Ubuntu 16.04 LTS
Database : MySQL 5.7.19-0ubuntu0.16.04.1 (Ubuntu)

Issue:
I was trying to upgrade my GOGS docker image from 0.9.x.x to latest version.
I followed the instructions:

  • docker pull gogs/gogs
  • docker stop gogs
  • docker rm gogs
  • docker run --name=gogs -p 10022:22 -p 10080:3000 -v /var/gogs:/data gogs/gogs

When I went to the url for gogs, I have the “Install Steps For First-time Run” page. Filled in the database settings as (except for pw, the rest are default settings) :
Database Type: Mysql
Host: 127.0.0.1:3306
User: root
Password : *****
Database Name: gogs

When I clicked Install Gogs, I get the error message:
Database setting is not correct: dial tcp 127.0.0.1:3306: getsockopt: connection refused

When I tried from command line: mysql -u root -p -h 127.0.0.1
I was able to enter MySQL without any error.

Thanks for the help


#2

Well, if Gogs says not able to connect, it is what exactly it means. I am not sure if you can connect to host MySQL instance inside a Docker container, people often start another container for MySQL specifically.


#3

When I installed gogs the first time months ago, I do not have this issue. The MySQL server is on the host machine while gogs is in Docker container. Ad I have been using Gogs for a few months. I just decide to upgrade the docker image as specified by the posted instruction, and can’t understand why it does not work the 2nd time around.
Is the database setting saying that Gogs is trying to connect to MySQL via 127.0.0.1:3306 from inside the docker container?


#4

It is possible!


#5

Issue fixed. I managed to find my config setting from my previous GOGS install. Since I’m using the docker version of GOGS, instead of the MySQL host being 127.0.0.1:3306, it should be 172.17.0.1:3306 since 172.17.0.1 being the bridge gateway IP for the container.

My guess is that the default settings for first time install assumes that MySQL and GOGS are both installed on the host server.


#6

I have the exactly same issue. But when I try 172.17.0.1 It reports error:

Database setting is not correct: Error 1130: Host '172.17.0.2' is not allowed to connect to this MariaDB server

#7

I’m getting this error now, but my settings are for sqlite3 so I shouldn’t be getting this at all right?

git clone git@<redacted>:geekingreen/resin-electronjs-react.git
Cloning into 'resin-electronjs-react'...
Gogs: Internal error
Fail to get repository owner 'geekingreen': dial tcp 127.0.0.1:3306: getsockopt: connection refused
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

any help would be appreciated :smiley:


#8

@geekingreen use absolute path for SQLite3 path.


#9

Even setting the sqlite DB with an absolute path it fails. It’s important to note that everything else works, just not git via SSH. I can login via the web, I can clone repos using https and a generated token (since I have 2FA enabled) I have validated that my public keys have been added appropriately via the web interface. But for whatever reason it throws this error when attempting git over SSH


#10

Figured it out, I had updated my install from using gogits/gogs to gogs/gogs and the command that was being run on ssh authentication was pointed to the old gogs executable. I had to update the git users .ssh/authorized_keys and replace command="/home/gogs/go/src/github.com/gogits/gogs/gogs serv key-18 --config='/home/gogs/go/src/github.com/gogits/gogs/custom/conf/app.ini'" with command="/home/gogs/go/src/github.com/gogs/gogs/gogs serv key-18 --config='/home/gogs/go/src/github.com/gogs/gogs/custom/conf/app.ini'". Hopefully this helps others that may run into this situation.