Answer the question
In order to leave comments, you need to log in
Can't load golang values into mysql database. how to solve it?
package main
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
)
func main() {
db, err := sql.Open("mysql", "mysql:[email protected](127.0.0.1:3306)/golang")
if err != nil {
panic(err)
}
defer db.Close()
insert, err := db.Query("INSERT INTO 'users' ('name', 'age') VALUES('alex', 43)")
if err != nil {
panic(err)
}
defer insert.Close()
fmt.Println("ok")
}
insert, err := db.Query("INSERT INTO 'users' ('name', 'age') VALUES('alex', 43)")
if err != nil {
panic(err)
}
defer insert.Close()
Answer the question
In order to leave comments, you need to log in
Your MySQL service is not running or MySQL is not listening to localhost:3306
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question