go-mysql 是一个功能强大的 MySQL 协议处理工具集,你可以使用 client 连接操作 MySQL,使用 server 制作自己的 MySQL proxy,使用 replication 同步 MySQL 的 binlog,使用 canal 进行 MySQL 到其他服务(Elasticsearch,Redis)的数据实时更新。
示例代码:
import ( "github.com/siddontang/go-mysql/client")// Connect MySQL at 127.0.0.1:3306, with user root, an empty passowrd and database testconn, _ := client.Connect("127.0.0.1:3306", "root", "", "test")conn.Ping()// Insertr, _ := conn.Execute(`insert into table (id, name) values (1, "abc")`)// Get last insert idprintln(r.InsertId)// Selectr, _ := conn.Execute(`select id, name from table where id = 1`)// Handle resultsetv, _ := r.GetInt(0, 0)v, _ = r.GetIntByName(0, "id")