I am having a problem with a golang project fetching data from MySQL database. This project has been working without issue until I upgraded from Ubuntu 16.04 to Ubuntu 18.04.01. The application now times out when connecting to the database.
My first thought was that something broke in the 16.04 to 18.04 upgrade. To prove this I spun up a new VM running 16.04, performed a "do-release-upgrade" and brought it up to 18.04. However on this VM, my application works just fine without problems.
I'm at a loss where to go from here to troubleshoot what is happening. Here is a summary of the two configurations. Both the VM (working) and the server (not working) are the following;
Ubuntu 18.04.01 LTS x86_64
Kernal 4.15.0-34-generic
Go 1.11
MySQL 5.7.23-0ubuntu
Here is my test program:
package main
import (
"fmt"
"database/sql"
_"github.com/go-sql-driver/mysql"
)
func main() {
fmt.Printf("Connecting to db
")
db,err := sql.Open("mysql","Test:@/Test")
if err != nil {
panic(err)
}
fmt.Printf("Trying query Row
")
var Data int
err = db.QueryRow("SELECT Data FROM Test WHERE ID=2").Scan(&Data)
fmt.Printf("After Query
")
if err != nil {
panic(err)
}
fmt.Printf("Got Data=%d
",Data)
db.Close()
}
On the VM the program executes without problem and returns some valid data. The server hangs on the QueryRow line. After 2 minutes I get this return
$ time ./test
Connecting to db
Trying query Row
After Query
panic: dial tcp 127.0.0.1:3306: connect: connection timed out
goroutine 1 [running]:
main.main()
/home/daedalus/test/sqltest.go:20 +0x263
real 2m10.874s
user 0m0.001s
sys 0m0.009s
I realize the problem is the program cannot connect to the database, or that the database does not respond, but I cannot see why. There is nothing being logged either in syslog, mysql's log files. There is nothing wrong with MySQL that I can see. I can connect and run queries as the Test user just fine.
I'm not sure how to proceed with tracking down why the server is failing but the VM is working when both configurations are the same.
Any help would be appreciated.