「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填錯了,坑!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM