Home >>Nodejs Tutorial >Node.js MySQL Create Database

Node.js MySQL Create Database

Node.js MySQL Create Database

The statement CREATE DATABASE is used for creating a MySQL database.

Example For creating a database named "Student".

Creating a javascript file called "connection.js" with the following data in the folder example1.

var db = require('db');  
var con = db.createConnection({  
host: "localhost",  
user: "root",  
password: ""  
con.connect(function(err) {  
if (err) throw err;  
con.query("CREATE DATABASE Student", function (err, result) {  
if (err) throw err;  
console.log("Database created");  

Now open the command terminal and execute the following command:

Node connection.js

The database is built for you to use.


To check whether or not the database is created use the command SHOW DATABASES. Before this, use mysql-p command to go to initial route.