Relational databases are some of the most well understood and common database options. MySQL and PostgreSQL are two of the most popular open-source relational databases. This recipe will demonstrate the database/sql package, which provides hooks for a number of relational databases and automatically handles connection pooling and connection duration, and gives access to a number of basic database operations.
This recipe will make use of a MySQL database to establish a connection, insert some simple data, and query it. It will clean up the database after use by dropping the table.
Getting ready
Configure your environment according to these steps:
- Download and install Go 1.12.6 or greater on your operating system athttps://golang.org/doc/install.
- Open a Terminal or console application, create a project directory such as ~/projects/go-programming-cookbookand navigate to this directory....