-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hope API for ConnectionID() #946
Comments
It is impossible in current database/sql design. |
Thank you for your reply! // at `packets.go` `readInitPacket()`
// connection id [4 bytes]
pos := 1 + bytes.IndexByte(data[1:], 0x00) + 1 + 4
connectionId := int(binary.LittleEndian.Uint32(data[pos-4 : pos])) Thanks again! |
I can't understand your question. Could you explain what you want in application? Note that you don't use this driver directly, but uses |
Whenever I execute a statement, I want to get the connection id.
But I have to get it many times (possibly tens of thousands of times), |
Go golang/go#29835. |
May I ask: why do you want the Connection ID from the driver? |
I need a Connection ID to resolve the mysql binlog log and it will execute multiple times. |
Thank you everyone, the problem has been solved! func (s *session) Raw(sqlStr string) (rows *sql.Rows, err error) {
// retry 3 times
for i := 0; i < maxBadConnRetries; i++ {
rows, err = s.db.DB().Query(sqlStr)
if err == nil {
return
} else {
log.Error(err)
if err == mysqlDriver.ErrInvalidConn {
err = s.initConnection()
if err != nil {
return
}
} else {
return
}
}
}
return
} func (s *session) initConnection() (err error) {
name := "mysql"
// retry 3 times
for i := 0; i < maxBadConnRetries; i++ {
if err = s.db.Exec(fmt.Sprintf("USE `%s`", name)).Error; err == nil {
// reset thread id
s.threadID = 0
return
} else {
if err != mysqlDriver.ErrInvalidConn {
log.Error(err)
return
}
}
}
if err != nil {
log.Error(err)
}
return
} |
When I create a connection, I want to get the connection ID, which may have been multiple times.
Is it possible to implement
ConnectionID()
?Poor efficiency when using
select connection_id()
multiple timesConfiguration
Go version: go 1.12
Server version: MySQL 5.7.19
Server OS: CentOS7
The text was updated successfully, but these errors were encountered: