Databases MYSQL
"github.com/1nput0/go-crypto-tracker/assets"
_ "github.com/go-sql-driver/mysql"
SQL=root:root@tcp(127.0.0.1:3307)/DatabaseName// Load the connection url .env to a variable in Go
err := godotenv.Load()
if err != nil {
log.Fatalf("err loading: %v", err)
}
connection_url := os.Getenv("SQL")
// Connect to mysql and open a database
db, err := sql.Open("mysql", connection_url)
if err != nil {
panic(err.Error())
}
// Close the connection to the database at the end of the function
defer db.Close()Important things to know
Last updated