Last active
August 26, 2017 23:57
-
-
Save murachi1208/92eacdfb76ac9687c42217f78e13631b to your computer and use it in GitHub Desktop.
はじめての Go言語、インストール&さわってみる,MySQLにアクセスしてみる その1 ref: http://qiita.com/murachi1208/items/9ab2cb101a4eba3037ee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export GOROOT=$HOME/go | |
export GOPATH=$HOME/go/goroot | |
export PATH=$PATH:$HOME/go/bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ go get "github.com/go-sql-driver/mysql" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
fmt.Println("Hello hage!!") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"database/sql" | |
"fmt" | |
_ "github.com/go-sql-driver/mysql" | |
) | |
func main() { | |
db, err := sql.Open("mysql", "user:password@tcp(host:3306)/dbname") | |
if err != nil { | |
panic(err.Error()) | |
} | |
defer db.Close() | |
rows, err := db.Query("SELECT TABLE_NAME, PARTITION_NAME FROM INFORMATION_SCHEMA.PARTITIONS where PARTITION_NAME is not null") | |
defer rows.Close() | |
if err != nil { | |
panic(err.Error()) | |
} | |
for rows.Next() { | |
var tableName string | |
var partitionName string | |
if err := rows.Scan(&tableName, &partitionName); err != nil { | |
panic(err.Error()) | |
} | |
fmt.Println(tableName, partitionName) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment