Connecting and persisting to a MySQL database
SQL stands for Structured Query Language and is a standard for communicating with relational databases. Both MySQL (https://www.mysql.com/) and PostgreSQL (https://www.postgresql.org/) are popular and open source Relational Database Management Systems (RDBMSes). There are many implementations of SQL databases, and each of them have their extensions and proprietary features. However, there is a base set of commands for storing, updating, and querying data implemented across all of these SQL databases.
In this recipe, we're going to communicate with a MySQL database from Node.js using the mysql
module.
Getting ready
First, we need to get a MySQL database running locally. To do this, and for the other databases in this chapter, where possible, we will use Docker. MySQL provides a Docker official image on Docker Hub (https://hub.docker.com/_/mysql). This recipe assumes some, but minimal, prior knowledge of SQL and relational databases...