K
K
Kagtaviy2016-06-08 16:25:45
MySQL
Kagtaviy, 2016-06-08 16:25:45

How to solve problem with go + mysql?

Hello, the problem is there is a problem with mysql.
I connect like this

db, err := sql.Open("mysql", "user:[email protected](myip:3306)/db_name?tls=skip-verify&autocommit=true")

I use:
_ "github.com/go-sql-driver/mysql"
"database/sql"
Then
stmt, err := db.Prepare("INSERT userinfo SET username=?,departname=?,created=?")
res, err := stmt.Exec("one", "two", "2012-12-09")
id, err := res.LastInsertId()
fmt.Println(id)

in mysql table
CREATE TABLE `userinfo` (
    `uid` INT(10) NOT NULL AUTO_INCREMENT,
    `username` VARCHAR(64) NULL DEFAULT NULL,
    `departname` VARCHAR(64) NULL DEFAULT NULL,
    `created` DATE NULL DEFAULT NULL,
    PRIMARY KEY (`uid`)
);

The compiler does not swear, but when calling the function:

http: panic serving 91.240.84.39:37623: dial tcp 91.240.84.39:3306: getsockopt: connection refused

Please tell me how to solve this problem.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Pavlyuk, 2016-06-08
@Kagtaviy

Check that mysql is running and is really listening on the given port at the given address. You just have an error connecting to the database.

V
Vitaly Filinkov, 2016-06-08
@vitfil

The problem is not with go + mysql, but with [self-censorship] ... Why are you ignoring the error in this line?
Yes, and the rest too.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question