gpt4 book ai didi

go - 构建命令行参数 : cannot load go-sql-driver/mysql

转载 作者:行者123 更新时间:2023-12-01 22:17:34 33 4
gpt4 key购买 nike

我有一个错误

build command-line-arguments: cannot load go-sql-driver/mysql: malformed module path "go-sql-driver/mysql": missing dot in first path element

而应用程序代码是
package main

import "database/sql"
import _ "go-sql-driver/mysql"

func main() {
db, err := sql.Open("mysql", "root:xxx@(127.0.0.1:3306)/dbname?parseTime=true")
err := db.Ping()
}

我已经完成了 go get -u github.com/go-sql-driver/mysql , 和 go.mod已更新,看起来不错。

有人可以帮助解决这个问题吗?

最佳答案

将导入更改为:

import _ "github.com/go-sql-driver/mysql"

Go 导入必须具有导入模块的完整路径。

关于go - 构建命令行参数 : cannot load go-sql-driver/mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58581713/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com