speedtest-go icon indicating copy to clipboard operation
speedtest-go copied to clipboard

Cannot open MySQL database

Open alexanderfefelov opened this issue 5 years ago • 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

Links

  • go-sql-driver/mysql#427

alexanderfefelov avatar Oct 18 '20 03:10 alexanderfefelov

I'm not really sure about this issue, is this Docker specific?

maddie avatar Nov 10 '20 08:11 maddie

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.

etfeet avatar Feb 20 '21 02:02 etfeet

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)"

BeanLiu1994 avatar Mar 08 '21 06:03 BeanLiu1994

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.)

https://github.com/librespeed/speedtest-go/blob/158e37d3ae14b971f3fe03f26164e93bbfaa5f5e/database/mysql/mysql.go#L14

// connectionStringTemplate = `%s:%s@%s/%s?parseTime=true`
connectionStringTemplate = `%s:%s@tcp(%s:3306)/%s?parseTime=true`

yas-nyan avatar Dec 22 '21 21:12 yas-nyan