Nodejs Mysql Create table

Similar to previous section, we will use the mysql query for create table.

Create a file “node-mysql-create.js” with below code.
var db = require('mysql');  
var con = db.createConnection({  
host: "localhost",  
user: "root",  
password: "password" 
database : "student" 
});  
con.connect(function(err) {  
if (err) throw err;  
console.log("Connected!");  
con.query("create table emp(id int,name varchar(100))", function (err, result) {  
if (err) throw err;  
console.log("Table created");  
});  
}); 

Below SS shows the output of this program.

node mysql create query

Below SS shows output from Mysql Database.

node mysql create output

Subscribe Now