从mysql客户端发送到mysql服务端的请求。总会经历TCP/IP请求的几个阶段。(图来源 TCP/IP详解 )
写一个简单代码,使得mysql服务器端主动断开连接:
import (
"database/sql"
_ "fmt"
_ "github.com/go-sql-driver/mysql"
//"time"
)
func main() {
db, err := sql.Open("mysql", "root:password@tcp(IP:3306)/gotest")
checkErr(err)
stmt, err1 := db.Prepare("INSERT INTO gotest (id) VALUES (?)")
checkErr(err1)
_, err = stmt.Exec(1)
checkErr(err)
select {
}
}
func checkErr(err error) {
if err != nil {
panic(err)
}
}
采用 tcpdump tcp port 3306 and -i ens160 host IP ,抓取来自客户端的连接。
00:52:59.426666 IP 10.4.209.45.51346 > MGRtest.mysql: Flags [S], seq 3500273362, win 8192, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0
00:52:59.426822 IP MGRtest.mysql > 10.4.209.45.51346: Flags [S.], seq 136139368, ack 3500273363, win 29200, options [mss 1460,nop,nop,sackOK,nop,wscale 7], length 0
00:52:59.427505 IP 10.4.209.45.51346 > MGRtest.mysql: Flags [.], ack 1, win 513, length 0
00:52:59.428488 IP MGRtest.mysql > 10.4.209.45.51346: Flags [P.], seq 1:79, ack 1, win 229, length 78
00:52:59.429705 IP 10.4.209.45.51346 > MGRtest.mysql: Flags [P.], seq 1:106, ack 79, win 512, length 105
00:52:59.429751 IP MGRtest.mysql >