Connecting and sending SQL to a MySQL server
Structured Query Language has been a standard since 1986, and it's the prevailing language for relational databases. MySQL is the most popular SQL relational database server around, often appearing in the prevalent Linux Apache MySQL PHP (LAMP) stack.
If a relational database was conceptually relevant to our goals in a new project, or we were migrating a MySQL-backed project from another framework to Node, the third-party 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
Let's grab mysql
, which is a pure JavaScript (as opposed to C++ bound) MySQL client module:
npm install [email protected]
We'll need a MySQLserverto connect to. By default, the mysql client module connects to localhost
, so we'll have MySQL
running locally
Note
Including @2.x
after mysql
ensures that we install the most up-to-date minor version of the second major version...