go连接操作mysql示例代码

代码语言:golang

所属分类:其他

代码描述:go连接操作mysql示例代码,使用github.com/go-sql-driver/mysql包

代码标签: mysql 示例

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

package main

import (
    "database/sql"
    "fmt"
    _ "github.com/go-sql-driver/mysql"
)
/*
 * Tag... - a very simple struct
 */
type User struct {
    ID   int    `json:"id"`
    Username string `json:"name"`
}
func main() {
  
    // Open up our database connection.
    db, err := sql.Open("mysql", "guest:p6yhG8iDRMNxdJ9w@tcp(localhost:3306)/guest?charset=utf8")

    // if there is an error opening the connection, handle it
    if err != nil {
        fmt.Println(err.Error())
    }
    

    // Execute the query
    result.........完整代码请登录后点击上方下载按钮下载查看

网友评论0