Languages
[Edit]
EN

Node.js - MySQL Create database

0 points
Created by:
Dirask JS Member
3460

In this article, we would like to show you how to create a MySQL database in Node.js.

const mysql = require('mysql');

const connection = mysql.createConnection({                    // gets connection with database
    host: 'localhost', //  '127.0.0.1'
    user: 'root',
    password: 'password',
    database: 'my_database',
});

connection.connect(error => {
    if (error) throw error;
    const query = 'CREATE DATABASE ??';
    const databaseName = 'my_database';
    
    connection.query(query, databaseName, (error, result) => { // sends queries and receives results
        connection.end();                                      // closes connection
        if (error) throw error;
        console.log(result);
    });
});

Node.js - MySQL

Native Advertising
­čÜÇ
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé

Join