Skip to content

Instantly share code, notes, and snippets.

@narenaryan
Last active June 21, 2016 03:56
Show Gist options
  • Select an option

  • Save narenaryan/c1bbe695b815b7a1703889bb2ff62120 to your computer and use it in GitHub Desktop.

Select an option

Save narenaryan/c1bbe695b815b7a1703889bb2ff62120 to your computer and use it in GitHub Desktop.
package main
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
)
func main() {
db, err := sql.Open("mysql", "root:passapp@tcp(127.0.0.1:3306)/gotest")
if err != nil {
fmt.Println(err.Error())
}
defer db.Close()
// make sure connection is available
err = db.Ping()
if err != nil {
fmt.Println(err.Error())
}
stmt, err := db.Prepare("CREATE TABLE person (id int NOT NULL AUTO_INCREMENT, first_name varchar(40), last_name varchar(40), PRIMARY KEY (id));")
if err != nil {
fmt.Println(err.Error())
}
_, err = stmt.Exec()
if err != nil {
fmt.Println(err.Error())
} else {
fmt.Println("Person Table successfully migrated....")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment