linux虚拟机说明
C:\LinuxVM\CentOS7_2 没有安装docker ssh root@192.168.43.53
[root@localhost ~]# mysql -uroot -p -h127.0.0.1 -P3306
-bash: mysql: command not found
[root@localhost ~]# yum update
Total download size: 363 M
Is this ok [y/d/N]: y #在手机热点下会耗费3GB左右的流量,请谨慎操作
Downloading packages:
C:\LinuxVM\CentOS7 安装了docker、mysql ssh root@192.168.43.137
[root@localhost ~]# mysql -uroot -p -h192.168.43.137 -P3306
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.27 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]>
centos 7安装golang1.12.5
[root@localhost ~]# wget https://studygolang.com/dl/golang/go1.12.5.linux-amd64.tar.gz
[root@localhost ~]# tar -zxf go1.12.5.linux-amd64.tar.gz -C /usr/local
[root@localhost ~]# mkdir /home/gopath
[root@localhost ~]# go version
-bash: go: command not found
在/etc/profile文件末尾添加以下配置,输入 :wq保存
这里的GO111MODULE配置是go1.11后出的一种新的包管理go modules方式代替vendor机制,可以不需要GOPATH,项目代码也不一定要放在GOPATH下面 可参考https://www.cnblogs.com/apocelipes/p/9534885.html
GO111MODULE=auto 自动
GO111MODULE=on 使用go modules,不会在vendor和gopath找依赖 【推荐新版都用这种】
GO111MODULE=off 使用vendor 或者gotpath
#golang env config
export GO111MODULE=on
export GOROOT=/usr/local/go
export GOPATH=/home/gopath
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
[root@localhost ~]# source /etc/profile
[root@localhost ~]# go version
go version go1.12.5 linux/amd64
[root@localhost ~]# go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/gopath"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build638824280=/tmp/go-build -gno-record-gcc-switches"
[root@localhost ~]#
[root@localhost hello]# touch test_mysql.go
[root@localhost hello]# cd ..
[root@localhost gotest]# go mod init gotest
go: creating new go.mod: module gotest
[root@localhost gotest]# go mod tidy
go: finding github.com/go-sql-driver/mysql v1.7.0
go: downloading github.com/go-sql-driver/mysql v1.7.0
go: extracting github.com/go-sql-driver/mysql v1.7.0
[root@localhost gotest]# cd hello
[root@localhost hello]# ls
hello hello.go test_mysql.go
[root@localhost hello]# go build test_mysql.go
# github.com/go-sql-driver/mysql
/home/gopath/pkg/mod/github.com/go-sql-driver/mysql@v1.7.0/nulltime.go:36:15: undefined: sql.NullTime
note: module requires Go 1.13
修改:require github.com/go-sql-driver/mysql v1.6.0
[root@localhost hello]# go build test_mysql.go
go: finding github.com/go-sql-driver/mysql v1.6.0
go: downloading github.com/go-sql-driver/mysql v1.6.0
go: extracting github.com/go-sql-driver/mysql v1.6.0
[root@localhost hello]# go build test_mysql.go
[root@localhost hello]# ls
hello hello.go test_mysql test_mysql.go
[root@localhost hello]# ./test_mysql
id name password point is_online is_lock
map[id:1 is_lock:0 is_online:0 name:1 password:c4ca4238a0b923820dcc509a6f75849b point:0]
map[id:2 is_lock:0 is_online:0 name:2 password:c4ca4238a0b923820dcc509a6f75849b point:0]
map[id:3 is_lock:0 is_online:0 name:3 password:c4ca4238a0b923820dcc509a6f75849b point:0]