Node.js MySQL - Create Database
MySQL package is used to create database in mysql using node js.
CREATE DATABASE database name mysql statement is used to create new databse in mysql database.
Example :
const mysql = require('mysql');
const db = mysql.createConnection({
host: "localhost",
user: "root",
password: "*******"
});
// connect to database
db.connect((err) => {
if (err) {
throw err;
}else{
console.log('Connected to database!');
db.query("CREATE DATABASE prodb", function (err, result) {
if (err) throw err;
console.log("New Database created!");
});
}
});
//Output : Connected to database! New Database created!
Comments