Cannot open MySQL database
Opened this issue · 4 comments
Log:
time="2020-10-18T05:22:30+03:00" level=info msg="Fetched server coordinates: 55.866500, 38.443800"
time="2020-10-18T05:22:30+03:00" level=fatal msg="Cannot open MySQL database: default addr for network 'mysql-main-master.backpack.test' unknown"
Environment
- speedtest-go 1.1.1
- Docker (Dockerfile, run script)
Links
I'm not really sure about this issue, is this Docker specific?
I'm getting this issue as well
Environment:
OS: Ubuntu 18.04 lts virtual machine
go version: 1.14.2 linux/amd64
kernel: 4.15.0-135-generic
ive tried using the hostname as well as the ip address (with and without mysql port included) . and both result in the following error:
INFO[0000] Fetched server coordinates: 32.715700, -117.164700
FATA[0000] Cannot open MySQL database: default addr for network 'my-dns-hostname' unknown
database_hostname="my-dns-host"
database_hostname="my-dns-host:3306"
database_hostname="127.0.0.1"
database_hostname="127.0.0.1:3306"
database_hostname="localhost"
database_hostname="localhost:3306"
All of the above produce the same connection error on startup. It seems like its failing to resolve dns. However, the os itself is able to do it just fine...
I've also tried adding a host file entry for ip dns record in /etc/hosts. However, it still produces the same error.
in https://github.com/go-sql-driver/mysql#examples
connection string is set as following:
id:password@tcp(your-amazonaws-uri.com:3306)/dbname
so database_hostname should be set in this format :
database_hostname="tcp(your-amazonaws-uri.com:3306)"
FYI, I found that by writing the configuration file as shown below, everything works without any problems.
database_type="mysql"
database_hostname="tcp(127.0.0.1:3306)"
database_name="speedtest"
database_username="speedtest"
database_password="EXAMPLEPASSWORD"
We may need to add this "MySQL-specific configuration" to the README, or rewrite the code for connecting to MySQL as follows. (Of course, this is a dirty example.)
speedtest-go/database/mysql/mysql.go
Line 14 in 158e37d
// connectionStringTemplate = `%s:%s@%s/%s?parseTime=true`
connectionStringTemplate = `%s:%s@tcp(%s:3306)/%s?parseTime=true`