Connecting and persisting to a MySQL database
SQL is a standard for communicating with relational databases. Both MySQL (https://www.mysql.com/) and PostgreSQL (https://www.postgresql.org/) are popular open source relational database management systems (RDBMSs). There are many implementations of SQL databases, and each of them has its extensions and proprietary features. However, there is a base set of commands for storing, updating, and querying data implemented across all these SQL databases.
In this recipe, we’re going to communicate with a MySQL database from Node.js using the mysql2
(https://www.npmjs.com/package/mysql2) 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.
...