Flash cards
Review the key moves
1/4
Core idea
What is the main idea behind Node.js MySQL Create Database?
Lesson checks
Practice each idea before moving on
Short Mimo-style checks built from this lesson's code, terms, and sequence.
1Quick choice
Which statement best captures the main point of this lesson?
2Fill blank
Complete the missing token from the example code.
___ mysql = require('mysql');3Order
Put the learning moves in the order that makes the concept easiest to apply.
Create a database named "mydb":
To create a database in MySQL, use the "CREATE DATABASE" statement:
Creating a Database
Creating a Database
To create a database in MySQL, use the "CREATE DATABASE" statement:
Example
Create a database named "mydb":
let mysql = require('mysql');
let 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");
});
});Save the code above in a file called "demo_create_db.js" and run the file:
Run "demo_create_db.js"
C:\Users\
Your Name
>node demo_create_db.jsWhich will give you this result
Connected! Database created