报错如下:
C:\Users\admin>go get github.com/go-sql-driver/mysql
go: go.mod file not found in current directory or any parent directory.
'go get' is no longer supported outside a module.
To build and install a command, use 'go install' with a version,
like 'go install example.com/cmd@latest'
For more information, see https://golang.org/doc/go-get-install-deprecation
or run 'go help get' or 'go help install'.
原因,本地的go环境配有配置好,需要执行以下命令go env -w GO111MODULE=auto重新设置go的环境配置,大小写需要注意
C:\Users\admin>go env -w GO111MODULE=auto
然后再次执行上次的安装命令
C:\Users\admin>go get github.com/go-sql-driver/mysql
就能看到,咱们安装好的Mysql驱动已经下载好了在环境变量GOPATH的目录下
如果不知道环境变量在哪里,可以通过这个命令go env查看
C:\Users\admin>go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\admin\AppData\Local\go-build
set GOENV=C:\Users\admin\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\admin\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\admin\go
set GOPRIVATE=
set GOPROXY=https://goproxy.cn,direct
set GOROOT=D:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=D:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.18.4
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set GOWORK=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\admin\AppData\Local\Temp\go-build3154357095=/tmp/go-build -gno-record-gcc-switches
我的在C:\Users\admin\go
这样Go中的mysql驱动配置就安装好了,可以进行开发了
补充:你需要把Mysql的驱动包拷贝到,Goland的src目录下,这样才能在Goland编译器中使用Mysql的驱动
F:\BaiduNetdiskDownload\Goland2020_55404\GoLand 2020\goland_2020.1.1_Portable\src