「golang」panic: commands out of sync. Did you run multiple statements at once
【问题现象】
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:%v@tcp(%v:%v)/%v?charset=utf8", user, pwd, host, port, dbName)
db := sqlx.MustOpen("mysql", str)
if err := db.Ping(); err != nil { // 检查连接性
return nil, err
}
db.SetMaxIdleConns(maxIdle)
return db, nil
}
【问题解决】
这个提示很是误导了我,实际上,问题原因是port填错了,坑!