Solution to Activity 7.1
The solution to this activity is as follows:
- Using your text editor, create a Node.js script and save it as
motdatabase.js
. Enter the following code into the script file to createMOTdatabase
:var mysqlconnection = require("./mysqlconnection.js"); mysqlconnection.query("CREATE DATABASE 'MOTdatabase'", function (err) if (err) throw "Problem creating the database:- " + err.code; console.log("Database created"); process.exit(); });
Note
The complete script can be found at https://github.com/PacktWorkshops/The-MySQL-Workshop/blob/master/Chapter07/Activity7.01/Activity_5_01_Solution_Create_Database.js.
This code will start by connecting to the database using the mysqlconnection.js
file. Once the connection is established, the program runs a query to create the MOTdatabase
database.
- Run the
motdatabase...