librespeed / speedtest-go

Go backend for LibreSpeed
GNU Lesser General Public License v3.0
706 stars 153 forks source link

Cannot open MySQL database #12

Open alexanderfefelov opened 3 years ago

alexanderfefelov commented 3 years ago

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

maddie commented 3 years ago

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

etfeet commented 3 years ago

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.

BeanLiu1994 commented 3 years ago

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

yas-nyan commented 2 years ago

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`