go get github.com/go-sql-driver/mysql
go get github.com/lib/pq
无论是安装那一条都会报错,错误大致如下:
.../connection_go18.go:43: undefined: driver.TxOptions
.../connection_go18.go:55: undefined: sql.IsolationLevel
.../connection_go18.go:69: undefined: driver.NamedValue
.../connection_go18.go:88: undefined: driver.NamedValue
网上搜了好久,原因大概是安装了老版本(1.7)的go,后来又安装了新版本(1.8.3)的go。
解决办法:删除/usr/local/go,$GOPATH/pkg。重新安装go。
删除命令如下:
sudo rm -rf /usr/local/go
sudo rm -fr $GOPATH/pkg
付原地址:https://github.com/go-sql-driver/mysql/issues/638