Тёмный

NextJS MySQL example. Get MySQL data into a react app using Node JS 

Digital CEO
Подписаться 3,6 тыс.
Просмотров 44 тыс.
50% 1

Опубликовано:

 

15 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 83   
@devinsmith4713
@devinsmith4713 2 месяца назад
8 hours of my life (of which I still didn't succeed in) summed up in 25 minutes. Now I can get on with the meat of my project. Thank you.
@noctua7771
@noctua7771 Год назад
You, good sir, have saved me from failing my final project. Thanks!
@hooleymcknight
@hooleymcknight Год назад
This was the only helpful thing after hours of digging. Seriously, thank you!!
@thedigitalceo
@thedigitalceo Год назад
Wowza! I should definitely do more. I’ve always used MySQL and can’t stand switching to MongoDB for no good reason at all. MySQL is hands down one of the best databases on the market
@BartMolkenboer
@BartMolkenboer Год назад
Didn't know MySQL DB connections with NextJS was possible, great to know so I can now really finally quit using handwritten PHP/ HTML and css and start fully developing my projects in NextJS with MySQL! Thanks for this clean tutorial man 🙏
@thedigitalceo
@thedigitalceo Год назад
Yes man!!! That’s exactly what happened to me. I wanted to transition to react and NextJS but I felt like I had to be stuck with MongoDB or NoSQL and learned it but I hated it. Then wait a second. React can connect to SQL databases too! It just seems most of the ecosystem isn’t talking about it much which was annoying
@BartMolkenboer
@BartMolkenboer Год назад
@@thedigitalceo I will be testing it out in the near future to see and checkout the speed of the MySQL db together with NextJS and typescript, wonder if it will affect the loading speeds much or not
@BattleGn0me
@BattleGn0me Год назад
that's what I do. I feel like it's the brute force entry level approach. I've been hand coding CSS, HTML, and JS in node.
@Sweetironman
@Sweetironman 2 года назад
Brother, You don't really know how happy I'm now after seeing this video 🤩 fantastic tutorial solve so many problems.
@dontforgetruby6397
@dontforgetruby6397 Год назад
The best video ever to help with NextJS MySQL, it is really beginner-friendly, thanks!
@leicodaya4660
@leicodaya4660 Год назад
thanks , i really needed this ,hope you have a great day
@hruday-ranjan
@hruday-ranjan 2 года назад
Thanks alot for this content bro.. 😘 ❤️ From India
@jonelilajas1084
@jonelilajas1084 Год назад
You save me this is the most useful thing that I really want to know. I ask chatGPT. but it cant give the me the right answer. Thank you God bless you brother.
@andreporto7451
@andreporto7451 Год назад
Simply the best everything I've ever seen, and without the complications that everyone seems to want to impose. Question: do you intend to make one for CRUD? For us, who are veterans, coming from coding completely different from the proposal lately, it would help a lot!
@thedigitalceo
@thedigitalceo Год назад
I just made a complete tutorial on CRUD. It’s the latest on my channel.
@bombastickss
@bombastickss Год назад
i love your video, that's so simple to understand. thank you so much dude
@TheDroppersBeats
@TheDroppersBeats Год назад
GOD BLESS MYSQL2! Thank you so much, boss!
@Pandesaltosino
@Pandesaltosino 2 года назад
holy, this is so advanced lmao. thanks. exactly what I needed though! Incredible work!!!!!!
@thedigitalceo
@thedigitalceo 2 года назад
You got it! Me and you must be the only people who wanted to use MySql with React and NextJS! Haha. I’ve always loved MySQL since the php Wordpress days and wanted to keep in my workflow.
@aw-zz5yo
@aw-zz5yo Год назад
Pretty good explanation. Thanks.
@thedigitalceo
@thedigitalceo Год назад
Thank you. I try 😎
@Kumar-Nitesh
@Kumar-Nitesh Год назад
You deserve my subscription
@ipodhelper401
@ipodhelper401 Год назад
I have a question regarding the images part. I tried doing that with my own database, but it won't work though it's on my own local system. I have images not appearing. I have the pictures stored on my Desktop as well as the "public" directory on my coding. What do I do?
@thedigitalceo
@thedigitalceo Год назад
It’s probably mislinked. Try to load the image file direct in the browser from your localhost app and see if you can pull up the direct file
@Great_Meditation
@Great_Meditation 6 месяцев назад
No HTTP methods exported in 'D:\digitalceo\src\app\api\getdata oute.js'. Export a named export for each HTTP method. i am facing while connecting to mysql database.
@excalibur2417
@excalibur2417 2 года назад
Thank you for this fantastic tutorial!
@leof240
@leof240 10 месяцев назад
I keep receiving an error of dbconnection.execute is not a function. any pointers to what the cause might be? Thanks in advance
@BlackIce31337
@BlackIce31337 5 месяцев назад
why you define function within useEffect? and then call it right after that?
@remitheguik1303
@remitheguik1303 Год назад
Thank you! Your video very help me!
@kablaamjam8089
@kablaamjam8089 2 года назад
Thanks dude, helped me a lot!
@baselnabelsi9536
@baselnabelsi9536 Год назад
where did you get the socketpath?
@AlTearjen
@AlTearjen Год назад
great video!
@scottnoring2960
@scottnoring2960 Месяц назад
How old is this. Is it NextJS14? I'm getting errors with usestate and useffect.
@blackwidow8447
@blackwidow8447 Год назад
This was soo helpful, thank you. But I'm facing a problem. I'm using MariaDB and it seems that only the first row of the table is being fetched, that too without the array format. Any tips to solve this will be highly appreciated. 😭
@parmetra
@parmetra 11 месяцев назад
Same problem...
@sbdev5853
@sbdev5853 2 года назад
Based on this tutorial, I was able to use Next.js with MySQL for a redesign of a site. I have a new concern. This site is well data-driven. I'm making a profile page that used at least 50 queries to the database. Cause of this, refreshing the page takes at least 20 seconds to load the data. It does show up correctly. For every query, I put each in a useState array. Will using server-side props be better to lower the time data to reach the page? Also, will Redux help with having so many useState statements? Appreciate the feedback as I have seen nobody show how to get data from MySQL using regular SQL queries. Only GraphQL and I'm not knocking it. I still like plain MySQL.
@thedigitalceo
@thedigitalceo 2 года назад
Yes definitely use getServerSideProps instead of useEffect. I have a tutorial on that on my channel here ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-D-U0OkP5kwg.html I showed and do use useEffect but going forward getServerSideProps is the way to go in NextJS. With getServerSideProps you’ll get all the data before the page loads and you don’t need to rely on useEffect or useState with it. As for the time it should really depend on how long it’s taking to get all the data. Are you using the Api/ folder with node to pull the data. If so if you go directly to the Api url and see how long does it take to get all the data there? And compare with the front end page. 20 seconds doesn’t seem right but 50 queries also seems like a ton of requests unless this is a massive app. Also be sure to be combining tables in your SQL where you can to reduce the amount of requests.
@sbdev5853
@sbdev5853 2 года назад
@@thedigitalceo I am in the api folder. As far as the queries, this is only one part that deals with a lot of them (over 800 maybe). I wanted to get one part working, then go to town after that. I believe it's a big site. I'm combining tables in my queries as well. It's the exact queries I'm using on my live site now other than changing the names of the queries. From the [id].js page, fetching the data from the api took 23.5 secs. The data shows up and the page is working. However, calling from the api URL (getdata-lib-router) like you suggested, I'm getting an {error: "Bind parameters must not contain undefined. To pass SQL NULL specify JS null"}. Luckily I kept the file (getdata-lib) you did before adding in the router portion of the code, as able to get the one query in 1ms. On the getdata-lib-router api, I took all the other queries except the 1st one, same error. Used the updated api/lib-router code from your repo. Went line by line only changing to my query to still get the bind parameters error. So this binding parameters error could be the issue. Thanks for the suggestions and help.
@BlackIce31337
@BlackIce31337 5 месяцев назад
another thing not mentioned here is- dont close mysql connection after every single query, Id put that anywhere else (even not into useEffect end when dismounting), if your app is using mysql everywhere- just dont disconnect from it
@ferlynrulete4049
@ferlynrulete4049 11 месяцев назад
Next Js deploy to vercel but how about mysql2, how to deploy?
@erinkahn4228
@erinkahn4228 Год назад
I'm trying to follow this using nextjs13, but stuck at the use router part where I want to show only 1 product on the single product pages with the [] brackets.Are you going to make a version in next 13?
@thedigitalceo
@thedigitalceo Год назад
This should work in next 13 if using pages directory. I’m not following exactly where are you stuck and what have you got working so far
@Gabriel-ue3jf
@Gabriel-ue3jf Год назад
How did you create the database inside phpmyadmin on the server? Did you use XAMPP/Wamp or something else?
@thedigitalceo
@thedigitalceo Год назад
You can create in the phpmyadmin ui itself
@danielsandnes6210
@danielsandnes6210 2 года назад
Would this be susceptible to SQL injection attacks? That id variable looks juicy for SQL injection, but I'm not too familiar with this stack, so I wouldn't know. With the LAMP stack we have Prepared Statements, does this work in a similar way?
@thedigitalceo
@thedigitalceo Год назад
I don’t believe so but we should test!
@thrasherflu
@thrasherflu Год назад
I'm using windows and I don't have the mysql.sock file. Can you help me?
@thedigitalceo
@thedigitalceo Год назад
I’m not sure for Windows. Try googling around but I seen someone say it can be left empty on windows. I wonder if that works. socket = ""
@thrasherflu
@thrasherflu Год назад
@@thedigitalceo yes, I solved it by leaving it empty
@thedigitalceo
@thedigitalceo Год назад
@@thrasherflu 👍🏼
@alikurniawan6389
@alikurniawan6389 Год назад
Not working sir, when I try to POST to mysql then I got an alert "ERROR INTERNAL SERVER 500"
@mugesoft
@mugesoft 4 месяца назад
Why the sql query executed twice?
@ksn425
@ksn425 Год назад
vdo on react/nextjs sequelize mysql2 connection setup
@radhagupta2358
@radhagupta2358 2 года назад
Thanks for your tutorial...Its amazing.. I have one questions - is it possible to use react redux with next.js and make all api calls at one place?
@thedigitalceo
@thedigitalceo 2 года назад
Thanks you very much for the kind words. Appreciated!
@jonu96
@jonu96 Год назад
Got a question, basically I already have a database, where my site is hosted with real entries. Can I use that DataBase on localhost to work with real entries?
@thedigitalceo
@thedigitalceo Год назад
Yes. That’s what I do. Just put the real credentials to that db in the variables
@jonu96
@jonu96 Год назад
@@thedigitalceo Thank you, maybe i'm doing something wrong. Do I need to install/run some mysql service on local?
@thedigitalceo
@thedigitalceo Год назад
@@jonu96 i would make sure that the connection to your remote database actually works first. Try MySQL workbench and make sure you can simply connect to the database with the right credentials/settings. Once that gives you a successful connection use those settings in the project. I’ve had this issue before and realized my credentials and settings were not authenticating on the remote serve.
@jonu96
@jonu96 Год назад
@@thedigitalceo i made it, didn't know i need to add my ip to remote MySQL from cPannel :) thank you
@thedigitalceo
@thedigitalceo Год назад
@@jonu96 great 👍🏼
@BattleGn0me
@BattleGn0me Год назад
Ugh. I'm not an engineer or a full stack developer. I'm a 3d artist Three.js jockey with a basic bitch AAS in SE that needs to post interactive content and I cant afford the time to constantly learn new frameworks. I just want to arrange a basic stack to serve a modest scale of payload and clients. I'm trying to build communication toolsets for internal communication, client management and product approval for use by our sales and project managers.
@sbdev5853
@sbdev5853 2 года назад
Thanks for the tutorial. Add me to that list. I have been trying forever to covert a PHP/MySQL site using react (in this case NextJS) where I didn’t have to covert to mongo. My question, I followed this tutorial and the changes you made in your repo. It displays the data correctly from the DB to the browser. However, when running the server in the terminal, I received this as a message: API resolved without sending a response for /api/getdata-lib-router, this may result in stalled requests. Is that an error or shouldn’t be concerned about it? If so, how should I fix that? What I did differently from your tutorial is I’m connecting to a remote database online, not local. Also, I’m not using bluebird. Any help would be appreciated.
@thedigitalceo
@thedigitalceo 2 года назад
I've seen this. I updated the repo as well. Assuming everything else is ok that error may come from a stalled connection back to the API prior to the router. If you add this as the first line in the useEffect for the product/[id] page it should stop the stalled request: if (!router.isReady) return; I noticed this error only happens with the router. Hope that helps! I'll also leave some notes in the description.
@sbdev5853
@sbdev5853 2 года назад
@@thedigitalceo That did it. I remember seeing that line before in some other videos but couldn't remember when to use it. That being said, YOU DON'T UNDERSTAND HOW MANY YEARS I HAVE BEEN WAITING FOR A SOLUTION LIKE THIS. I've trying to move a site from PHP to one on these Jamstack. I have a database with over 15 years of info. When I don't get all of it, I understood most of what you were saying to get the info to get a little data showing. Now, I spend on doing some of the more complex SQL queries I have. Another question for you. What are your recommendations for any books, videos, or resources about better learning React and Next.js? This is the Jamstack & front-end framework I want to get better at. Again, I can't express how happy your tutorial made me. You have a new subscriber.
@thedigitalceo
@thedigitalceo 2 года назад
I'm glad it helped. I also come from the history of Wordpress, PHP, jQuery, and I feel your sentiments. React and the jamstack can really be a whole new way to engineer sites and most RU-vid tutorials are people who came right into the jamstack as their first mode of study and don't connect the dots for people who were building with the older frameworks. Ironically, with new frameworks like NextJS the jamstack is making a full circle and we're going back to server side rendering like PHP again using Node js! Which is what got me excited to really get into React. I hope in the future, if I have the time, I can teach a course myself on React and NextJs and teach it more for people coming from the vanilla side of building websites. Thank you for taking the time to drop a comment. It's appreciated.
@sbdev5853
@sbdev5853 2 года назад
​@@thedigitalceo Not connecting the dots has been what bothering the most with most of the videos that I have seen. Never saw it that way with the rendering. Keep up the good work.
@SAS-qq5ce
@SAS-qq5ce Год назад
great content but you just butchered the db column naming convention :D. Anyways lots of love for the content
@thedigitalceo
@thedigitalceo Год назад
Thanks! I don’t like underscores 😂
@dg3152
@dg3152 Год назад
do a tutorial with nextjs trpc and mysql2😀
@thedigitalceo
@thedigitalceo Год назад
I’m honestly more of a vanilla NextJS guy. I make my own Api using the Api routes and connect right to MySQL database. I hardly find any reason to complicate it further. ☺️
@dg3152
@dg3152 Год назад
@@thedigitalceo thanks for answering, thats fair enough.
@tonyvito5062
@tonyvito5062 Год назад
How to insert data tho ?
@thedigitalceo
@thedigitalceo Год назад
Check my NextJS MySQL Crud tutorial
@tonyvito5062
@tonyvito5062 Год назад
@@thedigitalceo thanks man I'm coming from PHP and I got used to MYSQL
@thedigitalceo
@thedigitalceo Год назад
@@tonyvito5062 me too!
@it.sawang
@it.sawang Год назад
mysql2 to many connection
@camilocespedes6749
@camilocespedes6749 Год назад
Loved the video, but you should really consider not trying so hard to emphasize the "this is not hard even though people think it is", i couldn't even count the times I heard that phrase, it was getting annoying
@thedigitalceo
@thedigitalceo Год назад
how many times did I say it
@LarreLandin
@LarreLandin 2 года назад
This is a great tutorial, I am fairly new to NextJS and really learned a lot. However I got one error after following your instructions almost to the point (I used an existing database with members instead of products): When rendering my page I get the error "TypeError: Cannot read properties of undefined (reading 'map')" and in my console I noticed "API resolved without sending a response for /api/getdata-lib, this may result in stalled requests." I found out that it has something to do with the code in getdata-lib.js running twice and the first time there is no "id" parameter passed to the function. I can add a null check for "id" but I would like to understand why this happens. Any idea what could be the issue here?
@thedigitalceo
@thedigitalceo 2 года назад
Yes I've seen this. If you add this as the first line in the useEffect for the product/[id] page it should stop the stalled request: if (!router.isReady) return; I noticed this error only happens with the router. Hope that helps! I left the notes in the description. It’s because the fetch is happening before the route id has started so you have to add a condition to make sure the fetch starts only after the router id is returned
@LarreLandin
@LarreLandin 2 года назад
@@thedigitalceo Worked like a charm, thanks!
@iBlockchainChannel
@iBlockchainChannel 2 года назад
Can you please create tutorial of how to clone and deploy Token Airdrop dApp , this is the project GitHub link: github.com/SniperProject/Token-Airdrop-dApp Thanks for your effort
Далее
Куда пропали ЗДРАЙВЕРЫ?
11:38
Просмотров 599 тыс.
Real respect sig
00:48
Просмотров 1,3 млн
Моя Бывшая - Зомби Вернулась!
24:45
Node.js is a serious thing now… (2023)
8:18
Просмотров 646 тыс.
MySQL Node.js Express
28:03
Просмотров 179 тыс.
Fetching Data Doesn't Get Better Than This
6:58
Просмотров 116 тыс.
10 common mistakes with the Next.js App Router
20:37
Просмотров 212 тыс.
The Story of Next.js
12:13
Просмотров 576 тыс.
React Node.js MySQL CRUD Tutorial for Beginners
46:27
Просмотров 301 тыс.
Next.js App Router Caching: Explained!
25:22
Просмотров 94 тыс.
Don't Use Websockets (Until You Try This…)
6:46
Просмотров 301 тыс.
Куда пропали ЗДРАЙВЕРЫ?
11:38
Просмотров 599 тыс.