Have you downloaded our eBook, Building Database Driven Apps with Go? It is the best resource to quickly learn how to connect a database from Go programs.
This excerpt presents a quick introduction to the major functionality of database/sql in the form of a fully functioning Go program.
Before you begin, ensure you have access to a MySQL database, as we’ll use MySQL for the example. If you don’t have an instance of MySQL that’s appropriate for testing, you can get one in seconds with the MySQL Sandbox utility.
Create a new Go source file, hello_mysql.go, with the following source code (download). You may need to adjust the connection parameters as needed to connect to your testing database. Note …
[Read more]