MySQL Database connection from node js application
HTML-код
- Опубликовано: 17 дек 2019
- In This video I have shown how to connect MySQL database from node js Application.
1. create node project "npm init -y"
2. install mysql package "npm install mysql"
3. create a file like "database.js"
4. import mysql package "const { createPool } = require('mysql')"
5. create pool connection
-----------------------------------------
const pool = createPool({
host: "localhost",
user: "root",
password: "",
database: "test",
connectionLimit: 10
})
6. execute query
---------------------------
pool.query(`select * from registration`, function(err, result, fields) {
if (err) {
return console.log(err);
}
return console.log(result);
})
Thank you sir. It took me an hour of adjusting with ports to make it work. Thank you for the tutorial.
This has been the easiest and the best I have watched thank you for this
Thanks man, you don't know how much i appreciate these kind of tutorials!!
thank you very much , it worked . I was struggling to connect it but my struggle ends here ,once again thanks.
Very useful for beginners, thanks for making bro ❤️
Life saver, Spent weeks already
Very helpful for beginners, Thank you so much
Thank you for this video, very useful for solving this issue and connecting mysql to node js.
simple and to the point. thanks bro.
Thank you so much, you deserve more subs!
thanks for the tutorial.. I have one doubt do we need to end the connection if we are using the pool connection. If yes when do we do that???
thank you so much sir Was indeed helpful.
very clear and neat description
Thank u so much, it helped me a lot
thank you very much. this help me very much
Thanks from Brazil!
Very helpful. Thank you
Are we able to fetch data from MySQL database in Html table without API. Like in PHP we able to fetch data in HTML table without api using PHP loop. Could we do that same using node?? Or API is compulsory to show data with node js??
Thanks for good example
What happened when multiple query executed ? I mean How many connection established to DB Server in multiple query execution ?
Thank you!
Thanks ..HELPFUL!!!!!!!!!!!!!!!!!!!
can you implement sequelize with this rest? thanks
very helpful thank you
thanks dude its so helpful
Thank you so much
Thank you very much sir
Great video, solved my problem
can you tell me how to store that in a variable
could you please create an app with NODE + SQL Server? thanks!
Also show us that from where we have to create the database
Thanks bro
Thank u sir
Nice
What more can I ask for?
Thanks bro.
how do i print the result
thanks!!
how you will do though index.hrml file
how to give data to data base from the website
Why you did not show hos to install mysql on localhost?
how we display two table or more
Hello, In the same way I run the code but it showing something access denied error, could you please give explanation to this please,
E:\procedures_practice_server
ode_modules\mysql\lib\protocol\Parser.js:437
throw err; // Rethrow non-MySQL errors
^
Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
at Sequence._packetToError (E:\procedures_practice_server
ode_modules\mysql\lib\protocol\sequences\Sequence.js:47:14)
at Handshake.ErrorPacket (E:\procedures_practice_server
ode_modules\mysql\lib\protocol\sequences\Handshake.js:123:18)
at Protocol._parsePacket (E:\procedures_practice_server
ode_modules\mysql\lib\protocol\Protocol.js:291:23)
at Parser._parsePacket (E:\procedures_practice_server
ode_modules\mysql\lib\protocol\Parser.js:433:10)
at Parser.write (E:\procedures_practice_server
ode_modules\mysql\lib\protocol\Parser.js:43:10)
at Protocol.write (E:\procedures_practice_server
ode_modules\mysql\lib\protocol\Protocol.js:38:16)
at Socket. (E:\procedures_practice_server
ode_modules\mysql\lib\Connection.js:88:28)
at Socket. (E:\procedures_practice_server
ode_modules\mysql\lib\Connection.js:526:10)
at Socket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:324:12)
--------------------
at Protocol._enqueue (E:\procedures_practice_server
ode_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (E:\procedures_practice_server
ode_modules\mysql\lib\protocol\Protocol.js:51:23)
at PoolConnection.connect (E:\procedures_practice_server
ode_modules\mysql\lib\Connection.js:116:18)
at Pool.getConnection (E:\procedures_practice_server
ode_modules\mysql\lib\Pool.js:48:16)
at Object. (E:\procedures_practice_server\index.js:15:6)
at Module._compile (node:internal/modules/cjs/loader:1218:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
at Module.load (node:internal/modules/cjs/loader:1081:32)
at Module._load (node:internal/modules/cjs/loader:922:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
code: 'ER_NOT_SUPPORTED_AUTH_MODE',
errno: 1251,
sqlMessage: 'Client does not support authentication protocol requested by server; consider upgrading MySQL client',
sqlState: '08004',
fatal: true
}
Really helpful. Thanku so much
Thank you so much.😊
how do i output this on a browser??
I am not able to open vs code from command prompt
indian guy are smart
but how to connect cpanel mysql db?
I typed schema name instead of database name and then it retrieved data
Uncaught ReferenceError: require is not defined. Why is this happening? Everytime I use require in JavaScript I am stuck with this error.
MAYBE UR USING "TYPE":"MODULE" IN UR PACKAGE.JSON FILE
ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
Hey bro, did you find the solution to this?
Hello sir,
When I creating database connection it shows depreciation warning
[DEP0095] DeprecationWarning: timers.enroll() is deprecated. Please use setTimeout instead.
How to update
Delete
The system cannot find the path specified. why am i getting this?
Similar here , how do u solve it
Client does not support authentication protocol requested by server; consider upgrading MySQL client : Can someone help?
why are we using php if we can get data from mysql
run VS Code as administrator
When I type node .\database.js
It gives me
Code : 'ER_NOT_SUPPORTED_AUTH_MODE',
errno: 1251
sqlMessage: 'Client does not support authentication protocol requested by server; consider upgrading MySQL client',
sqlState: '00004' ,
fatal: true
}
Try this bro ./database.is
It should be forward slash
npm install mysql2
and then change mysql to mysql2 in the first line
Not working
this is fakhar
same here
ggg
chorrrrrrrrrrrr
worst
I follow your step, and WHY IT DID NOT WORK?!!!!!!!
at Function.Module._load (node:internal/modules/cjs/loader:813:14) {
code: 'PROTOCOL_SEQUENCE_TIMEOUT',
fatal: true,
timeout: 10000
} help me nrother
Thank you!