加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

「golang」panic: commands out of sync. Did you run multiple

发布时间:2020-12-16 09:30:57 所属栏目:大数据 来源:网络整理
导读:【问题现象】 go使用 go-sql-driver 连接mariaDB,如下,提示: panic: commands out of sync. Did you run multiple statements at once ? 示例: func NewMysqlDB(host string ,port int ,user ,pwd ,dbName string ,maxIdle int) (*sqlx. DB , error) { s

【问题现象】

go使用go-sql-driver连接mariaDB,如下,提示:

panic: commands out of sync. Did you run multiple statements at once

?

示例:

func NewMysqlDB(host string,port int,user,pwd,dbName string,maxIdle int) (*sqlx.DB,error) {
str := fmt.Sprintf("%v:%[email?protected](%v:%v)/%v?charset=utf8",host,port,dbName)

db := sqlx.MustOpen("mysql",str)
if err := db.Ping(); err != nil { // 检查连接性
return nil,err
}
db.SetMaxIdleConns(maxIdle)
return db,nil
}

【问题解决】

这个提示很是误导了我,实际上,问题原因是port填错了,坑!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读