Question

I am using the following package for MySQL

http://godoc.org/github.com/go-sql-driver/mysql#MySQLDriver.Open

And my code is:

import (
  "bufio"
  "database/sql"
  _ "github.com/go-sql-driver/mysql"
)

db, err := sql.Open("mysql", "me_id:username@tcp(db1.abc.com)/dataname?timeout=2s")

But I am getting the error message of error: dial tcp: missing port in address db1.abc.com

Is there anyway that I can specify the server without any port number? I am porting the oroginal code in Python and it has no port number.

Was it helpful?

Solution

As Mentioned by ANisus, the default port for MySQL is 3306.

Please try with:

db, err := sql.Open("mysql", "me_id:username@tcp(db1.abc.com:3306)/dataname?timeout=2s")

and see if that fixes the problem. The MySQL driver doesn't seem to provide a default port if one isn't specified.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top