How to Connect Node js to MySQL Database and Fetch Data in 5 minutes

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 พ.ย. 2024

ความคิดเห็น • 55

  • @תמרנידאם
    @תמרנידאם 2 ปีที่แล้ว +1

    תותח אלוףףףףףף
    ההסבר ממש מעולה ועוזר
    תודה!🙏

  • @MsamerieJohnson
    @MsamerieJohnson ปีที่แล้ว +7

    For those getting undefined, I used this code to connect to the database
    const mysql = require("mysql")
    //Create a Database Connection
    const con = mysql.createConnection({
    host:'localhost',
    user:'root',
    password:'your_password',
    database:'your_databse'
    })
    con.connect((err) => {
    if(err)
    {
    console.log(err)
    }else{
    console.log("CONNECTION SUCCESSFUL!")
    }
    })
    // Get The Data From The Table
    con.query('select * from your_table', (err, res) =>{
    return console.log(res)
    })

  • @williamdevonshire356
    @williamdevonshire356 ปีที่แล้ว

    awesome. finally i can connect the two!!! woo yea!!! Thank you sir :)

  • @nerolifong1824
    @nerolifong1824 ปีที่แล้ว +1

    short video and to the point. great job

  • @phantomak3r477
    @phantomak3r477 ปีที่แล้ว

    Quick and straight to the point.

  • @CorreaLobo
    @CorreaLobo 2 ปีที่แล้ว +1

    Hello Brother! Excellent Video, You just got a sub thank you so much. So simple and understandable. TY ❤❤

  • @LinXiaoChaun
    @LinXiaoChaun 2 ปีที่แล้ว +7

    At [02:39], I was at first thrown off by the destructuring syntax
    const {createPool}=require('mysql');
    const pool = createPool( { … } ) ;
    An equivalent (more pedestrian) alternative would be something like:
    const mysql = require('mysql') ;
    const pool = mysql.createPool( { …} )

  • @DiscussedFir6
    @DiscussedFir6 2 ปีที่แล้ว +1

    Thank you so much for this, great tutorial!

  • @bryantgarcia998
    @bryantgarcia998 ปีที่แล้ว +1

    Really useful video. By any chance, do you have a follow up video on how to post data to mysql work bench in javascript as well?

  • @Sukubus666
    @Sukubus666 ปีที่แล้ว +3

    For me it keeps saying 'undefined'. 😭 Could you help out how to fix that issue? I have node.js installed and triple checked if my code looks the same like in video.. 😕

  • @michelsolis6603
    @michelsolis6603 ปีที่แล้ว

    Thanks! And then? When you want to upload proyect to prod? What do I have to do to hide this information?

  • @Sami_Ljimari
    @Sami_Ljimari 3 ปีที่แล้ว +2

    very useful, thank you for making the video

  • @assetdev1859
    @assetdev1859 ปีที่แล้ว

    hey! great video. i have a question, if i want to deploy this website on vercel/heroku what I need to do? our sql data base located in localhost how correctly i understand so can we push it somewhere? something like cloud storage? thanks for the answer :3

  • @axsd1489
    @axsd1489 9 หลายเดือนก่อน +1

    Thanks for help

  • @_dejvy
    @_dejvy 2 ปีที่แล้ว

    really good tutorial, just one question, how can i default select database name

  • @rinkijain4517
    @rinkijain4517 24 วันที่ผ่านมา

    Greate sir

  • @wildriftgames1931
    @wildriftgames1931 ปีที่แล้ว +1

    why didn't work on my visual studio code when I'll run in terminal? Pls. help!!

  • @dimitriskosse1727
    @dimitriskosse1727 ปีที่แล้ว

    thank you bro

  • @nimeshpatilvlogs8629
    @nimeshpatilvlogs8629 2 ปีที่แล้ว

    Do we have to first create table insql

  • @goodluckoriuwa1669
    @goodluckoriuwa1669 10 หลายเดือนก่อน

    Can uou show how to connect node express app to online MySQL database

  • @realhistory765
    @realhistory765 2 ปีที่แล้ว

    Thank you bro ❤

  • @leonbou3959
    @leonbou3959 2 ปีที่แล้ว +3

    Hi, i want to store the return of the query in a variable. how can i make that work? When i write const x = (query) and instead of return console.log() just returning the res. It doesn't gave me back the result. Can anyone help me how to get the res returned to store it in a variable?

    • @LinXiaoChaun
      @LinXiaoChaun 2 ปีที่แล้ว

      In your code, before the call to pool.query, create a variable, say, foo, then assign it the value of res within the function body:
      var foo=[] ; pool.query( 'SELECT * FROM apidb.users', (err,res)=>{foo=Array.from(res)} ) ;
      The value of foo will now be the result of the mysql query.
      To confirm that this code is working, run node in your shell, entering REPL mode, then give it the REPL command '.load database.js'. Node will echo the content of the file database.js followed by the result of running that file.
      You will remain in REPL mode: you can give the REPL command "foo", and node will echo its value.
      End the session by typing

    • @sh44ko58
      @sh44ko58 2 ปีที่แล้ว

      @@LinXiaoChaun Why is it not working for me ? Btw i ive coded also something with react so dont be confused ;D
      const pool = createPool({
      host: "localhost",
      user: "root",
      password: ""
      })
      var foo = []
      pool.query(`SELECT * FROM appclone.user`, (err, res) => {foo=Array.from(res)} )
      res.json({"users": [foo] })
      Could you help me ?

  • @forester1
    @forester1 2 ปีที่แล้ว

    Can we query same like php api ?

  • @SITPonrajA
    @SITPonrajA ปีที่แล้ว

    Hey I have a error on require() function

  • @Dlo2018
    @Dlo2018 ปีที่แล้ว

    how do i create a node module?

  • @VarshaSivaramakrishnan
    @VarshaSivaramakrishnan ปีที่แล้ว

    i applied your code but it just displays undefined what do i do?

  • @mukkt
    @mukkt ปีที่แล้ว +2

    For anyone getting an authentication error:
    "npm install mysql2" then change the require statement to "mysql2"

  • @Maumau369
    @Maumau369 ปีที่แล้ว

    is require not defined anymore? i get "ReferenceError: require is not defined"

  • @jasonmiller1076
    @jasonmiller1076 2 ปีที่แล้ว +4

    mine said undefined

  • @yourmoveatheists
    @yourmoveatheists 2 ปีที่แล้ว

    🐐 Thank you!

  • @kashish9220
    @kashish9220 2 ปีที่แล้ว +5

    "undefined" occur as output of node database.js
    please help regarding this

    • @saadbinwasi3038
      @saadbinwasi3038 2 ปีที่แล้ว

      same did you find solution?

    • @nirmalgaur3228
      @nirmalgaur3228 2 ปีที่แล้ว

      Maybe your password is not "rootuser".

    • @timhoward5
      @timhoward5 2 ปีที่แล้ว

      @@nirmalgaur3228 Nope, because mines did the same thing and I used my password.

    • @mikahoy
      @mikahoy 2 ปีที่แล้ว

      It occurs because you haven't select the database where the table reside

    • @Pan_Jan_Wroclawski
      @Pan_Jan_Wroclawski 2 ปีที่แล้ว +6

      try to use mysql2 instead of mysql package

  • @Aman22506
    @Aman22506 2 ปีที่แล้ว

    can this apply in phpmyadmin

  • @forester1
    @forester1 2 ปีที่แล้ว

    Greate

  • @joeyGunz1-w1r
    @joeyGunz1-w1r 2 ปีที่แล้ว

    I am getting a 504 error when sending data to mysql in nginx

  • @rezaeiabazar5324
    @rezaeiabazar5324 ปีที่แล้ว

    ok

  • @koggism
    @koggism 11 หลายเดือนก่อน +1

    video is blured

    • @KindsonTheTechPro
      @KindsonTheTechPro  หลายเดือนก่อน

      I guess it is playing in lower resolution in your system, you need to play in a higher resolution