package main import ( "fmt" _ "github.com/go-sql-driver/mysql" "github.com/jinzhu/gorm" ) func main() { _, err := sqlConnect() if err != nil { panic(err.Error()) } else { fmt.Println("DB接続成功") } } // SQLConnect DB接続 func sqlConnect() (database *gorm.DB, err error) { DBMS := "mysql" USER := "go_example" PASS := "12345!" PROTOCOL := "tcp(localhost:3306)" DBNAME := "go_example" CONNECT := USER + ":"
![【第12回】Go言語(Golang)入門~MySQL接続編~ – 株式会社ライトコード](https://cdn-ak-scissors.b.st-hatena.com/image/square/6318e868f8b1662559c1104980ce8c4bc5763d22/height=288;version=1;width=512/https%3A%2F%2Frightcode.co.jp%2Fwp-content%2Fuploads%2F2019%2F11%2Fgolang-introduction-mysql-connection.png)