Connecting and sending SQL to a MySQL server
The Structured Query Language (SQL) has been a standard since 1986, and it's the prevailing for relational databases. MySQL is most popular SQL relational database server around, often appearing in the prevalent Linux Apache MySQL PHP (LAMP) stack.
If a relational database conceptually to our goals in a project, or we migrating a MySQL backed project from another framework to Node, the mysql
module would be particularly useful.
In this task, we will discover how to connect to a MySQL server with Node and execute SQL queries across the wire.
Getting ready
We'll need a MySQL server to connect to. By default, the mysql
client module connects to localhost, so we'll have MySQL running locally.
On Linux, we can see if MySQL is already installed with the following command:
$ whereis mysql
On macOS, we can use this:
$ type -a mysql
On Windows, we can use the GUI and check the package manager via the control panel.
We can see if the MySQL server is running...