go导入“github.com/go-sql-driver/mysql“连接失败错误解决

Hey,我是寅贝勒,后端开发一枚,欢迎来我的个人网站 www.ly-zone.cloud 一起学习交流~

在使用golang连接mysql数据库时需要用到go的数据库连接驱动

github.com/go-sql-driver/mysql

  • 首先需要在golang的终端输入
go get -u github.com/go-sql-driver/mysql

可能会出现如下错误
在这里插入图片描述

PS E:\Go\practice\PRO1> go get -u github.com/go-sql-driver/mysql
go: module github.com/go-sql-driver/mysql: Get "https://proxy.golang.org/github.com/go-sql-driver/mysql/@v/list": dial tcp 142.251.42.241:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
  • 这是因为无法对外网进行访问(开了VPN也不行),可以通过输入一下命令进入代理网站进行访问
go env -w GOPROXY=https://goproxy.cn,direct
  • 该结果无返回,然后再输入上述命令
go get -u github.com/go-sql-driver/mysql
  • 可以看到已经安装的版本号了
PS E:\Go\practice\PRO1> go get -u github.com/go-sql-driver/mysql   
go: downloading github.com/go-sql-driver/mysql v1.6.0
go: added github.com/go-sql-driver/mysql v1.6.0

你可能感兴趣的:(Go核心知识,mysql,golang,sql)