内容简介:模块安装代码数据库的数据内容
模块安装
go get -u github.com/go-sql-driver/mysql
代码
package main
import (
"database/sql"
_"github.com/go-sql-driver/mysql"
"log"
"fmt"
)
func main(){
db,err :=sql.Open("mysql","root:@tcp(127.0.0.1:3306)/nginxlog") //连接数据库
checkErr(err)
rows,err :=db.Query("select * from nginxlog limit 10; ")
checkErr(err)
for rows.Next(){
var id int
var ip string
var time string
var methods string
var source string
var protocol string
var status string
err = rows.Scan(&id,&ip,&time,&methods,&protocol,&status,&source)
checkErr(err)
fmt.Println(id,ip,time,methods,status,source)
}
}
//校验函数
func checkErr(err error){
if err != nil{
log.Println(err)
}
}
数据库的数据内容
Golang查询的结果:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 4 万字全面掌握数据库、数据仓库、数据集市、数据湖、数据中台
- Python3爬虫数据入数据库---把爬取到的数据存到数据库,带数据库去重功能
- Oracle数据库查询重复数据及删除重复数据方法
- sqlserver数据库获取数据库信息
- 从大数据到数据库
- node连接oracle数据库,更新数据后,数据库中不生效问题
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Concepts, Techniques, and Models of Computer Programming
Peter Van Roy、Seif Haridi / The MIT Press / 2004-2-20 / USD 78.00
This innovative text presents computer programming as a unified discipline in a way that is both practical and scientifically sound. The book focuses on techniques of lasting value and explains them p......一起来看看 《Concepts, Techniques, and Models of Computer Programming》 这本书的介绍吧!
CSS 压缩/解压工具
在线压缩/解压 CSS 代码
HSV CMYK 转换工具
HSV CMYK互换工具