NodeJS + MySQL Database Connection Tutorial

About this tutorial:

Video duration: 20:53
Learn how to do NodeJS + ExpressJS + MySQL database connection using XAMPP as MySQL database and querying data from database.

Post Author:

Apple lover, ICT and LEAN consultant, MS Office lecturer My other website with video tutorials - Tutorials, guides and news for iPhones and iPads

26 thoughts on “NodeJS + MySQL Database Connection Tutorial

    immaneni gowtham

    (September 18, 2019 - 2:36 am)

    ive tried the programm but the connection is not established and its coming as connection timedout.

    Nargesh Rana

    (September 18, 2019 - 2:36 am)

    Background noise is very disturbing.

    Madalin Dumitru

    (September 18, 2019 - 2:36 am)

    You scared me when you started to shout at the end!

    Iti Gamer

    (September 18, 2019 - 2:36 am)

    Very helpful but how can I connect it to HTML page

    Алёша Кирасинка

    (September 18, 2019 - 2:36 am)


    Ron Linder

    (September 18, 2019 - 2:36 am)

    I followed the instructions the only difference is I used my MySQL db located on a server online. How do I use express in that case to see the data? Like I can't use localhost:1337 since its not local.

    foday S

    (September 18, 2019 - 2:36 am)

    What the hell is up with the banging, do you have someone locked in the basement?


    (September 18, 2019 - 2:36 am)

    Thank you for tutorial!

    Maco Doussias

    (September 18, 2019 - 2:36 am)

    You're tutorial has been a great help to me. Thank you.


    (September 18, 2019 - 2:36 am)

    THANK YOU SO MUCH!! awesome tutorial, life saver


    (September 18, 2019 - 2:36 am)

    Why did you do (!!error) instead of just (error) ??????

    Goutham chand

    (September 18, 2019 - 2:36 am)

    Can u please provide me the link of this code. Thanks

    Ricardo Garcia

    (September 18, 2019 - 2:36 am)

    I'm getting require is not defined error…

    Saroj Moharana

    (September 18, 2019 - 2:36 am)

    Hi, can u pls publish video on how to connect teradata database using node.js. It's very important to me.


    (September 18, 2019 - 2:36 am)

    if(!!error) funny xD

    Saksham Bakshi

    (September 18, 2019 - 2:36 am)

    where to get the source code

    Neeraj Rawat

    (September 18, 2019 - 2:36 am)

    if database is in other system so how can we connect with other system to access their database


    (September 18, 2019 - 2:36 am)

    Well… I have just one database connection per server. And that's it. My HTTP server is talking with it ONLY when it's needed.

    Neha Kumari

    (September 18, 2019 - 2:36 am)

    can u pls help me

    throw err; // Rethrow non-MySQL errors

    Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: YES)
    at Handshake.Sequence._packetToError (C:UsershpDesktopdatanode_modulesmysqllibprotocolsequencesSequence.js:47:14)
    at Handshake.ErrorPacket (C:UsershpDesktopdatanode_modulesmysqllibprotocolsequencesHandshake.js:124:18)
    at Protocol._parsePacket (C:UsershpDesktopdatanode_modulesmysqllibprotocolProtocol.js:278:23)
    at Parser.write (C:UsershpDesktopdatanode_modulesmysqllibprotocolParser.js:76:12)
    at Protocol.write (C:UsershpDesktopdatanode_modulesmysqllibprotocolProtocol.js:38:16)
    at Socket.<anonymous> (C:UsershpDesktopdatanode_modulesmysqllibConnection.js:91:28)
    at Socket.<anonymous> (C:UsershpDesktopdatanode_modulesmysqllibConnection.js:502:10)
    at Socket.emit (events.js:182:13)
    at addChunk (_stream_readable.js:287:12)
    at readableAddChunk (_stream_readable.js:268:11)
    at Protocol._enqueue (C:UsershpDesktopdatanode_modulesmysqllibprotocolProtocol.js:144:48)
    at Protocol.handshake (C:UsershpDesktopdatanode_modulesmysqllibprotocolProtocol.js:51:23)
    at Connection.connect (C:UsershpDesktopdatanode_modulesmysqllibConnection.js:118:18)
    at Object.<anonymous> (C:UsershpDesktopdatadb.js:15:6)
    at Module._compile (internal/modules/cjs/loader.js:722:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10)
    at Module.load (internal/modules/cjs/loader.js:620:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
    at Function.Module._load (internal/modules/cjs/loader.js:552:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:775:12)

    Keytron Quabius

    (September 18, 2019 - 2:36 am)

    Note for myself. 12:33
    I'm a slow learner but I'm never stopping.
    Topicals: too many to list , understand theory, example, using phpMyAdmin instead of work bench. Basic theory, basic connection, but unsure of workflow each time/ each instance of start and population (so theory of, how that works, with the result, to code )
    Workflow for line 23 and how we adapt that for our own libs like sequelize and others. .

    How that affects the workflow of stop starting server more importantly each time we populate the app and what db server is doing (no theory, all code)

    Abhishek Khatri

    (September 18, 2019 - 2:36 am)

    Anybody tell me please how can we open nodejs (index.js) file without using port(.listen(8080)) and terminal. I want to open like php(index.php) I browse like localhost/mypath/index.php so i just want to browse directly ?? hope for better reply


    (September 18, 2019 - 2:36 am)

    Here is the working code:

    var mysql = require('mysql')
    var express = require('express')
    var app = express()

    var connection = mysql.createPool({
    connectionLimit: 50,
    host : 'host',
    user : 'user',
    password : 'pass',
    database : 'db'

    console.log("setting up route…")

    app.get('/', function(req, resp) {
    connection.getConnection(function(error, tempCont) {
    if(!!error) {
    } else {

    tempCont.query("select * from questions", function(error, rows, fields) {
    if(!!error) {
    console.log('Error in the query');
    } else {

    console.log("listening requests…")

    username taken

    (September 18, 2019 - 2:36 am)

    wheres the link to code lmao


    (September 18, 2019 - 2:36 am)

    I thank Christ for you. I went months trying to get a database connected with node or PHP and I always came close but things would break. Thank you. Thank you sir.

    I know this is probably simple, but this wasn't working for months.

    GauTam RaJput

    (September 18, 2019 - 2:36 am)


    ReferenceError: app is not defined

    R Nair

    (September 18, 2019 - 2:36 am)

    Excellent.. You made it easy. Thank you👍

Leave a Reply

Your email address will not be published. Required fields are marked *