mysql: query command can not to use *
os: fedora
this is my code
db, err0 := sql.Open("mysql", "root:123456@tcp(127.0.0.1:3306)/test")
if err0 != nil {
log.Fatal(err0)
}
defer db.Close()
//var row *sql.Rows
// row,err := db.Query("select * from user")
row,err := db.Query("select id,name,age from user")
if err != nil {
panic(err)
os.Exit(1)
// log.Fatal(err)
}
for row.Next() {
var id,age int
var name string
row.Scan(&id,&name,&age)
fmt.Println(id,"\t",name,"\t",age)
}
error log:
root@localhost gowork]# go run test.go
panic: runtime error: slice bounds out of range
goroutine 1 [running]:
github.com/go-sql-driver/mysql.(*mysqlConn).readColumns(0xc42008e000, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0)
/root/go/src/github.com/go-sql-driver/mysql/packets.go:693 +0xa33
github.com/go-sql-driver/mysql.(*mysqlConn).query(0xc42008e000, 0x60d623, 0x12, 0x729d08, 0x0, 0x0, 0x0, 0x0, 0x58b010)
/root/go/src/github.com/go-sql-driver/mysql/connection.go:408 +0x3cb
github.com/go-sql-driver/mysql.(*mysqlConn).QueryContext(0xc42008e000, 0x6f1160, 0xc420018118, 0x60d623, 0x12, 0x729d08, 0x0, 0x0, 0x7fc20e05b058, 0x4530c0, ...)
/root/go/src/github.com/go-sql-driver/mysql/connection_go18.go:72 +0x112
database/sql.ctxDriverQuery(0x6f1160, 0xc420018118, 0x7fc20e05b058, 0xc42008e000, 0x60d623, 0x12, 0x729d08, 0x0, 0x0, 0x429d89, ...)
/opt/go/src/database/sql/ctxutil.go:48 +0x277
database/sql.(*DB).queryDC.func1()
/opt/go/src/database/sql/sql.go:1320 +0x99
database/sql.withLock(0x6efda0, 0xc420092000, 0xc420051c50)
/opt/go/src/database/sql/sql.go:2873 +0x65
database/sql.(*DB).queryDC(0xc42007c140, 0x6f1160, 0xc420018118, 0x0, 0x0, 0xc420092000, 0xc420010690, 0x60d623, 0x12, 0x0, ...)
/opt/go/src/database/sql/sql.go:1319 +0x6ba
database/sql.(*DB).query(0xc42007c140, 0x6f1160, 0xc420018118, 0x60d623, 0x12, 0x0, 0x0, 0x0, 0x1, 0x6, ...)
/opt/go/src/database/sql/sql.go:1304 +0x147
database/sql.(*DB).QueryContext(0xc42007c140, 0x6f1160, 0xc420018118, 0x60d623, 0x12, 0x0, 0x0, 0x0, 0xc420051e50, 0xc420051e58, ...)
/opt/go/src/database/sql/sql.go:1281 +0xd2
database/sql.(*DB).Query(0xc42007c140, 0x60d623, 0x12, 0x0, 0x0, 0x0, 0x0, 0x58d40c, 0x60a70a)
/opt/go/src/database/sql/sql.go:1295 +0x82
main.main()
/data/src/gowork/test.go:57 +0x132
exit status 2
solve
change sql command “select * from user” to " select id from user "
can not to use * ?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 16 (8 by maintainers)
Thanks. I can comfirm your problem. Wireshark reports malfold MySQL packet. And I found similar issue is reported: https://bugs.mysql.com/bug.php?id=86318
As described in the issue report, adding
?query_cache_type=0to DSN can avoid the issue.Anyway, it seems bug of MySQL, not this project. But the behavior “malfold packet can cause panic, instead of returning error” may be a bug of this project.