This is a creation in Article, where the information may have evolved or changed.
Want to kill MySQL TCP, all external links are controlled by my proxy, so wrote a TCP to UNIX socket proxy.
Package Mainimport ("OS" "FMT" "Net" "io" "Sync" "Time") type proxy struct{host stringport stringlocal string}func runproxy ( list []proxy] {wg: = sync. Waitgroup{}for _, V: = Range List {WG. ADD (1) go func () {eachserver (V.host, V.port, v.local) WG. Done ()} ()}wg. Wait ()}func eachserver (host string, port string, local string) {l,err: = net. Listen ("TCP", FMT. Sprintf ("%s:%s", host, port)) if err! = Nil {fmt. Print ("Listen tcp:%s", err.) Error ()) OS. Exit (1)}defer l.close () for {tc,err: = l.accept () if err! = Nil {fmt. PRINTF ("Accept TCP Conn:%s", err.) Error ()) TC. Close () Continue}go eachconn (Local, TC)}}func eachconn (local string, TC net. Conn) {uc,err: = net. Dial ("Unix", local) if err! = Nil {fmt. Printf ("Get Unix Conn:%s", err.) Error ()) UC. Close () Return}go io. Copy (TC, UC) go IO. Copy (UC, TC)}func main () {list: = []proxy{proxy{host: "192.168.8.101", Port: "3306", Local: "/home/work/data/tmp/ Mysql3306.sock "}}runproxy (list)}