The database/sql package with MySQL
Relational databases are some of the most well understood and common database options. MySQL and Postgres are two of the most popular open source relational databases. This recipe will demonstrate the database/sql
package, a package that provides hooks for a number of relational databases and automatically handles connection pooling, connection duration, and gives access to a number of basic database operations.
The future versions of this package will include support for context and timeouts.
Getting ready
Configure your environment according to these steps:
- Download and install Go on your operating system from https://golang.org/doc/install, and configure your
GOPATH
environment variable. - Open a terminal/console application, navigate to your
GOPATH/src
and create a project directory such as$GOPATH/src/github.com/yourusername/customrepo
.
All code will be run and modified from this directory.
- Optionally, install the latest tested version of the code using the...