In this beginner-friendly tutorial, learn how to connect Drizzle ORM to MySQL for a job portal application using Next.JS. We cover essential steps like installing MySQL and Drizzle, creating a database in MySQL Workbench, setting up environment variables for DATABASE_URL, establishing the connection, and creating a connection pool. Includes a quick recap, next video preview, and tasks for practice. Perfect for developers building full-stack apps with TypeScript ORM.
⌛TIMELINE⏳ 0:00 – Drizzle connection with MySQL - Job Portal App 0:25 – Why you must watch Drizzle ORM tutorial 2:05 – Getting started with Drizzle + MySQL in Next.js 4:00 – Link to join React Live Classes 4:35 – Installing MySQL and Drizzle ORM 7:05 – Creating a database in MySQL Workbench 8:20 – Setting up .env file with DATABASE_URL 9:50 – Connect Drizzle ORM with MySQL database 11:20 – Creating a connection pool for Drizzle 13:20 – Quick recap of Drizzle ORM + MySQL setup 14:00 – Next video updates 14:15 – Task for you guys
Hello, what's up guys?
Welcome to your nextjs with mysql job portal application
Today is our day number 9
And today we are going to see how to connect our frontend with backend
What does it mean?
How can we connect nextjs with our database?
With mysql
And we will not only use mysql
We can use mysql in a better way
For that we are going to use Drizzle ORM
Now I want to clear one thing
I have already uploaded a full course on Drizzle ORM
I request you to check out this video
All your doubts will be cleared
What is Drizzle ORM?
And why are we using it?
Like you must have heard about Prisma
Just consider it as an alternative
Drizzle ORM is very lightweight
It is type-safe
Yes, guys
This is the beauty
Even in the database
What you are doing is
You are keeping type-safety
Like our best part of this project is
Whatever is happening here
We are using type-safety
Because of which we are able to type-safe here
Basically, what should be the type of every field?
Basically, we are talking about data type
We have taken care of that here
In the same way
Which field should be in the database?
And which data type value do you want to insert in that field?
Or put
In that
Our Drizzle ORM is very useful
So please check out this video once
Your life will definitely change
And the second best part of using Drizzle ORM is
Guys, when you code in Drizzle ORM
You will feel like you are coding in MySQL
Because both are very similar
Okay
So today we will see in our video
That our job portal application
In which we have already created the user interface of registration and login
Now we will connect it to our database
So that whoever fills the form here
The data goes to our database
But before that there is validation
There is a lot of things
We will see that
Okay
So today's video is very important
And again I am assuming
So first of all
Why are we using Drizzle ORM?
Because we are using MySQL here
Right
If you run on simple Drizzle like this
Then you can see something like this
Okay
Where you see
If you have support of JavaScript and TypeScript
Then I will run on Get Started
So here you have to tell
With which database are you dealing?
And for that you must be using Drizzle
So tell me the name of that database
So you can see
You get a lot of Postgres
And in the world of MySQL
We have a MySQL here also
Right
So I will click on this MySQL
So once I click on MySQL
So now you can see
I can see some interface like this
Basically their page
Where I will find three things
And that is the .env
Then we have this tsx
Obviously we are using TypeScript
And if you are not using TypeScript
You are using simple JavaScript
Then you can keep that here
Then we have this MySQL2
MySQL2 means
Normally we use MySQL
In the old days we used to work with PHP
In which we used to use JamServer
And we had to run there
Basically on
But in today's time
If you are doing on MonstaX
Or dealing with Next.js
Then like a simple package
Like npm install react
Or your TypeScript
Or your Jod
Or your React router
Similarly write npm install mysql2
Done
It's done
It's so easy
I mean it's done
But yes
Along with that
I would like to keep Workbench
Here on the side
So that it becomes a little easy for us
But one more best part of Drizzle is
That now you basically
There is no need for this
Because Drizzle provides you a Drizzle kit
Basically Studio
In which you can see everything easily
Okay
But still I have to create a database
Here
And you can see
Already we have done so much
Out of which
We have this drop database
Whatever it is
I will run it once and show you
Let's leave it for now
So first of all
Now in our job portal application
We install our database
But before that I would like to tell you one thing
Guys, it takes a lot of effort to make a video
So I want you guys to support me
Like the video
Share with friends
Whatever doubt you have in your mind
Or if you want to give any advice or suggestion
Then do tell by commenting
And if you haven't subscribed to the channel yet
Please do
And those who are interested
Live classes full stack
Of React
So guys
It's already going to start from Monday
So you have two more days in your hands
So do check out this video
You can see the link at the top
You can join me by whatsapp
Any online classes of React
You can ask me doubts regarding it
Next JS will also be fun
Check it out
Okay
So I'll go here
A little down
Their basic folder structure
You can see something like this
Okay
No doubt we do it now
First of all
We have to install packages
See
Again we have multiple ways
To install packages
Like
Which managers do you want
Like package manager
We have NPM
YARN
PNPM
And then burn
Guys burn is super fast
But I guess
You haven't installed it for a long time
And we are already doing this project through NPM
So I would like to select NPM
Okay
So I'll do one thing
I'll copy these two
I copied both
I'll go to my vscode editor
Here like this
I'll go here
Okay
I'll go to the other one
Basically
I open my second terminal
I'll open it
Something like this
Okay guys
I'll go here
I'm already inside my folder
What did I write there?
I didn't write anything
It's copy-paste
I want Drizzle ORM
MySQL 2
So that our database
I mean MySQL
And .env
By the way
We don't need .env
Like this
Alright
Okay
I can't do it directly
Okay
Let it be
I'll just install these two
Okay
Because
MySQL and Drizzle ORM
Are supported here
So this is getting installed
While this is getting installed
I'll do one thing
I'll copy this too
And then I'll be ready here
Now remember one thing
If I'm running on a file like package.json
So here
Right now in our script
We have like three scripts
And my dependency
Here you can't see MySQL
Or Drizzle ORM
You can't see it anywhere
Not even in our dev dependencies
You can't see it here
Okay
If I run here
Okay
Now you can see
It's getting installed
Let's wait a little
And oh my god
I just said
Like it's done
Okay
So now if I run here
So if we see here
So now you can see
We have this Drizzle ORM
You can see the version
Okay
And then we have this MySQL 2
You can see the version clearly
So Drizzle ORM is installed
MySQL 2 is installed
Now let's do one thing
If you want a Drizzle kit
So go here
And then paste it like this
Okay
So it will do its work
We don't have any tension
Let's go here
Once when you install any packages
No doubt we have to use it
But before using
We know very clearly
That we have to connect with our database
And before connecting with the database
You should have your own database
Right
So now our next step is
To create a database
In our MySQL Workbench
So let me do one thing
You can see here
Let me copy this
I have already made this database
Because I am already practicing
Side by side
That's why I will be able to tell you
Properly
So I am
Job portal
Which is written
Next
Underscore
Job portal
I am doing this
I am copying this
And you can see here
This icon
I am hitting run
And boom
Now you can see
That your database is created
That's it
This is it
For now
I only needed this
For this work
That I have to create a database
And by the way
That part
I could have done it easily
Through code
But
I thought
This was a kid's work
I wrote it quickly
And it's done
So why should I work so hard
For code
Right
So this way
We can create it very easily
And
One more thing
I will tell you again
You will think
That I am talking too much
But guys
For your benefit
I am telling you
There are more than 1 million views
6 years ago
I was uploading
Still the same
No changes
Right
So check it out
It will help you a lot
Right
And I have made a lot on
Nextjs with MySQL
So check it out
Right
So once my database is done
Now
What we need to do
We need to create a .env file
And
We have to create
The connection
Of our .env file
So
Here
It's important
How to create a connection
Right
So
Your file
Come here
.env file
It's outside
By the way
Right
So
I will go here
.env
I wrote .env
Here
They told me to do it
Right
I will copy it
Now
Alright
Now how do you know
What is yours
And
Like
The connection
Line
What is that line
So guys
It's your MySQL
Colon
Hyphen hyphen
Now you have to write root
Basically
Your username
By default
It's root only
Then you have to write
Your password
Alright
So
I will write my password
Then again
It's at the right
Then where do you run it
On server
Or localhost
Right
So it's a localhost
And then
You have to give
Its port number
It's 3306
And then forward slash
So
Now
Go here
Now
The name of your database
You have to include
What is the name of my database
Next
If I want
I will copy it from here
It will be better
Okay
And
Go here
I will paste it like this
Okay
There is no need to give any semicolon
Here
I will show you in one line
So
This is your MySQL
No doubt
You have to write
Your username
Your password
Then
Our localhost
Obviously
And then
The name of your database
Save it
Now guys
Finally
The time has come
Where
Our result
Our database
We are going to connect with it
Okay
So
It's very simple
You can see
Multiple options
Have been given to you
How do you want to do it
But
If I tell you
So
We can easily
This part
You can see
We can do with it
Now
Here
This file
You can see
Create a index.ts file
In the source
db directory
And initialize the connection
So
What do we have to do here
We have to go inside the source folder
Here
I will do one thing
Guys
I will use that
Funda
I will use the same file
In the config
db.ts
This file
I am creating
Okay
I am in the source folder
What did I do
Configuration
Basically
I created a folder
In config
In it
db.ts
Now
Inside it
My code
I will copy it
And then I will paste it
Now
Here
If you do this much
Then your work will be done
And by the way
Import.env
We don't need this
Because
By default
It is supported
So
Guys
You can see here
We are getting a warning
Because
I am not able to pass the string
Directly inside drizzle
And
It is telling
Because
We are using type script
So
Argument of type string
Or undefined
If I show you
So
Is not assignable
To a parameter
Of type string
This
That
This
Let it be
I will tell you
Let's do one thing
If it is not happening directly
Which happens
Later
Through
Jot validation
I will show you
For now
Let's do one thing
Let's create a pool
Ok
How to do
I will tell you
Const
Pool
And by the way
I have already uploaded a video on this
So
It's a MySQL
And then
You have to write 2
And
One second
2 is here
MySQL drizzle
ORM2
No
MySQL 2
How to get
I will tell you
Import
MySQL
To
From
We have a
MySQL
To
Forward slash
We have a
Promise
That's all you have to write
Then come here
Create a pool
Ok
Basically
Create pool
Already
There is a method
Go inside
Pass object
I am passing URI
In URI
Go
Ok
One property
Where is your process
Dot
ENV
Dot
This