本文介绍了(go-sql-driver / mysql)packets.go中意外的EOF和繁忙缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尽管设置完成后,我在 go-sql-driver / mysql
中出现意外的EOF和繁忙缓冲区
错误建议。任何人都可以告诉我这个问题的适当解决方案似乎没有为我工作?
db,err:= sql.Open( mysql,USERNAME:PASSWORD @ tcp(IP:PORT)/ DB?charset = utf8)
checkErr(err)
db.SetConnMaxLifetime(time.Second * 5)
db .SetMaxIdleConns(0)
db.SetMaxOpenConns(151)
rows,err:= db.Query(从col:col1,col2,col3 from tbl)
checkErr(err )
for rows.Next(){
var col1 string
var col2 int32
var col3 uint64
err = rows.Scan (& col1,& col2,& col3)
checkErr(err)
进程(col1,col2,col3)
}
$ c
解决方案我设置了一个本地MySQL数据库并运行你的代码:
package main
import(
database / sql
fmt
log
time
_github.com/go-sql-driver/mysql
)
func main(){
db,err:= sql.Open( mysql,root @ tcp(localhost)/ test?charset = utf8)
if err!= nil {
log.Fatalln(err)
}
db.SetMaxOpenConns(151)
rows,err:= db.Query($ b db.SetConnMaxLifetime(time.Second * 5)
db.SetMaxIdleConns(0)
db.SetMaxOpenConns SELECT(col1,col2,col3 FROM tbl2)
if err!= nil {
log.Fatalln(err)
}
for rows.Next(){
var col1 string
var col2 int32
var col3 uint64
err = rows.Scan(& col1,& col2,& col3)
如果错误!=无{
log.Fatalln(err)
}
fmt.Println(col1,col2,col3)
}
}
..它对我来说工作得很好。我的 CREATE TABLE
语句如下所示:
CREATE TABLE`tbl2` (
`col1` varchar(25)DEFAULT NULL,
`col2` int(11)DEFAULT NULL,
`col3` bigint(20)unsigned DEFAULT NULL
)ENGINE = InnoDB DEFAULT CHARSET = utf8;
您的表结构是什么样的?
I am getting the unexpected EOF and busy buffer
error in go-sql-driver/mysql
despite after setting the SetConnMaxLifetime
, SetMaxIdleConns
and SetMaxOpenConns
as suggested here. Can anyone tell me the proper solution of this issue nothing seems to work for me?
db, err := sql.Open("mysql", "USERNAME:PASSWORD@tcp(IP:PORT)/DB?charset=utf8")
checkErr(err)
db.SetConnMaxLifetime(time.Second * 5)
db.SetMaxIdleConns(0)
db.SetMaxOpenConns(151)
rows, err := db.Query("Select col1, col2, col3 from tbl")
checkErr(err)
for rows.Next() {
var col1 string
var col2 int32
var col3 uint64
err = rows.Scan(&col1, &col2, &col3)
checkErr(err)
Process(col1, col2, col3)
}
解决方案 I setup a local MySQL database and ran your code:
package main
import (
"database/sql"
"fmt"
"log"
"time"
_ "github.com/go-sql-driver/mysql"
)
func main() {
db, err := sql.Open("mysql", "root@tcp(localhost)/test?charset=utf8")
if err != nil {
log.Fatalln(err)
}
db.SetConnMaxLifetime(time.Second * 5)
db.SetMaxIdleConns(0)
db.SetMaxOpenConns(151)
rows, err := db.Query("SELECT col1, col2, col3 FROM tbl2")
if err != nil {
log.Fatalln(err)
}
for rows.Next() {
var col1 string
var col2 int32
var col3 uint64
err = rows.Scan(&col1, &col2, &col3)
if err != nil {
log.Fatalln(err)
}
fmt.Println(col1, col2, col3)
}
}
..and it worked just fine for me. My CREATE TABLE
statement looks like this:
CREATE TABLE `tbl2` (
`col1` varchar(25) DEFAULT NULL,
`col2` int(11) DEFAULT NULL,
`col3` bigint(20) unsigned DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
What does your table structure look like?
这篇关于(go-sql-driver / mysql)packets.go中意外的EOF和繁忙缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!