Delete MySQL Rows in Go

Posted by yhuang
Public (Editable by Users)
Go
None
Edit
package main

import (
	"database/sql"
	"log"

	_ "github.com/go-sql-driver/mysql"
)

func main() {
	db, err := sql.Open("mysql", "root:root@(127.0.0.1:3306)/root?parseTime=true")
	if err != nil {
		log.Fatal(err)
	}

	_, err := db.Exec(`DELETE FROM users WHERE id = ?`, 1)
	if err != nil {
		log.Fatal(err)
	}
}