go mod init gin
go mod edit -require github.com/gin-gonic/gin@latest
引入mysql驱动以后,引用包以后,写mysql代码,运行后报错。
mysql.go:6:2: cannot find module providing package github.com/go-sql-driver/mysql: working directory is not part of a mo
dule
用上面两个命令解决。仅供参考。并非万能。
下面是本人具体代码场景
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
)
func main() {
db, err := sql.Open("mysql", "xxx:xxx@tcp(localhost:3306)/golang01?charset=utf8")
if err != nil {
panic(err)
}