go 连接mysql数据库
来源:原创
时间:2019-03-31
作者:脚本小站
分类:GoLang
安装mysql驱动,在命令行中运行:
go get -u github.com/go-sql-driver/mysql
导入包:
package main import ( "database/sql" "fmt" _ "github.com/go-sql-driver/mysql" ) func main() { db, err := sql.Open("mysql", "root:root@tcp(localhost:3306)/test?charset=utf8") if err != nil { panic(err.Error()) } fmt.Println(db) }
使用示例:
https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/05.2.md