MySQL Create Database

Creating a Database

To create a database in MySQL, use the “CREATE DATABASE” statement:

Example

Create a database named “mydb”:

var mysql = require(‘mysql’);var con = mysql.createConnection({
host: “localhost”,
user: “yourusername“,
password: “yourpassword
});

con.connect(function(err) {
if (err) throw err;
console.log(“Connected!”);
con.query(“CREATE DATABASE mydb“, function (err, result) {
if (err) throw err;
console.log(“Database created”);
});
});

Run example »

Save the code above in a file called “demo_create_db.js” and run the file:

Run “demo_create_db.js”

C:UsersYour Name>node demo_create_db.js

Which will give you this result:

Connected!
Database created

THU HUYỀN – LINKPIZ.COM

SHARE

Leave a Reply

Next Post

MySQL Get Started

Tue Sep 27 , 2022
  Node.js can be used in database applications. One of the most popular databases is MySQL. MySQL Database To be able to experiment with the code examples, you should have MySQL installed on your computer. You can download a free MySQL database at https://www.mysql.com/downloads/. Install MySQL Driver Once you have […]