I'm trying to insert a row into a MySQL table:
package main
import (
"strconv"
"io/ioutil"
"strings"
"os/exec"
"database/sql"
_ "github.com/go-sql-driver/mysql"
)
func main() {
temp_cpu := getCPUTemp() // returns float32
temp_gpu := getGPUTemp() // returns float64
db, err := sql.Open("mysql", "user:pass@/sysStats")
handleError(err)
_, err = db.Query("INSERT INTO temperatures (id, cpu, gpu, timestamp) VALUES (?, ?, ?, ?)", 1, temp_gpu, temp_cpu, time.Now())
handleError(err)
db.Close()
return
}
It builds successfully but when I run the resulting binary it just times out after a long time with a generic timeout error.
The table has the following schema:
+----------------+-----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+-----------+------+-----+---------+-------+
| idtemperatures | int(11) | NO | PRI | NULL | |
| cpu | float | YES | | NULL | |
| gpu | float | YES | | NULL | |
| timestamp | timestamp | YES | | NULL | |
+----------------+-----------+------+-----+---------+-------+
I am running this on the same server the MySQL instance is hosted and I can access the database with the user/password from the terminal.
Any help?
Thanks!