SlideShare a Scribd company logo
Session IV
©Techforce Infotech Pvt Ltd 2017-18
You have to install MySQL driver to access a MySQL database with
Node.js. Download MySQl module from npm.
To download and install the "mysql" module, open the Command Terminal
and execute the following:
 Ex:-
Connection with MySQL
npm install mysql
Create a js file named "connection.js" having the following
code:
 connection.js:-
Connection with MySQL
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost", //host address
user: "root", // username of mysql
password: "12345" //password of mysql
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});
Now run a js file named "connection.js".
Now open the command terminal and use the following
command:
 connection.js:-
Connection with MySQL
node connection.js
INSERT INTO statement is used to insert records in MySQL.
Insert Record
var insertquery = "insert into tbl_student(id,name,age)
values ?";
var values = [
[null, 'abc', 22],
[null, 'def', 55]
];
mysql.query(insertquery, [values], function(err,
result)
{
if (err) throw err;
console.log('Record inserted');
});
The UPDATE command is used to update records in the
table.
Update Record
var sql = "UPDATE tbl_student SET age = 25 WHERE id=1";
con.query(sql, function (err, result) {
if (err) throw err;
console.log(result.affectedRows + " record(s) updated");
});
The DELETE FROM command is used to delete records from
the table.
Delete Record
var sql = "DELETE FROM tbl_student WHERE name =
‘xyz’ ";
con.query(sql, function (err, result) {
if (err) throw err;
console.log("Number of records deleted: " +
result.affectedRows);
});
The SELECT command is used to retrieve data from the
table.
Select Record
var sql = "SELECT * from tbl_student";
con.query(sql, function (err, result) {
if (err) throw err;
console.log(result);
});
The DROP TABLE command is used to delete or drop a table.
Drop Table
var sql = "DROP TABLE tbl_student";
con.query(sql, function (err, result) {
if (err) throw err;
console.log("Table deleted");
});
Session IV completed
Address: 403, Venus Benecia, Bodakdev,Ahmedabad –
380053
Reach us : reach@techforceinfotech.com
Contact no: +91 (79) 48904529

More Related Content

PPTX
Node Session - 2
ODP
Node js presentation
PPT
Nodejs quick start
PDF
Webpack101
PDF
Visual Programming Framework for Unity - UniFlow のご紹介
PDF
An Introduction to node.js
PDF
Rails入门培训
PDF
How to setup and connect my sql to ec2 instance from ubuntu
Node Session - 2
Node js presentation
Nodejs quick start
Webpack101
Visual Programming Framework for Unity - UniFlow のご紹介
An Introduction to node.js
Rails入门培训
How to setup and connect my sql to ec2 instance from ubuntu

What's hot (20)

TXT
Msi list
PDF
PLNOG16: Automatyzacja tworzenia sieci w środowisku Vmware, Maciej Lelusz
PPTX
NodeJs Session02
PPTX
NodeJs Session03
PPTX
Nodejs Session01
PDF
Meteor Meets Mallory
PDF
virtualization course content
TXT
Sql related links
PPTX
Redis fundamental
PDF
Node js实践
DOCX
Solaris mysql sop
KEY
An Introduction to Node.js Development with Windows Azure
PPTX
Codemash - Building Custom node.js Modules
PPTX
Dprn3 u3 a1_ocov
PPTX
Running Node Applications on iOS and Android
ODP
MySQL and SSD
PDF
Cookies in Angular | Install CookiesService
PDF
Open wrt seminar
PPTX
AKS: Keep your Devs close and your OpsSec closer…
TXT
Wlst deployment library
Msi list
PLNOG16: Automatyzacja tworzenia sieci w środowisku Vmware, Maciej Lelusz
NodeJs Session02
NodeJs Session03
Nodejs Session01
Meteor Meets Mallory
virtualization course content
Sql related links
Redis fundamental
Node js实践
Solaris mysql sop
An Introduction to Node.js Development with Windows Azure
Codemash - Building Custom node.js Modules
Dprn3 u3 a1_ocov
Running Node Applications on iOS and Android
MySQL and SSD
Cookies in Angular | Install CookiesService
Open wrt seminar
AKS: Keep your Devs close and your OpsSec closer…
Wlst deployment library
Ad

Similar to Node Session - 4 (16)

PDF
Node.js with MySQL.pdf
PPTX
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
PPTX
harry presentation
PDF
MySQL as a Document Store
PDF
Mysql Cookbook Solutions For Database Developers And Administrators 4th Editi...
PDF
Mysql Cookbook Solutions For Database Developers And Administrators 4th Editi...
PPTX
Discover the Power of the NoSQL + SQL with MySQL
PPTX
Discover The Power of NoSQL + MySQL with MySQL
DOCX
Based on the materials for this week, create your own unique Datab.docx
PPTX
Unit IV database intergration with node js
PDF
Developing for Node.JS with MySQL and NoSQL
PDF
Open Source World June '21 -- JSON Within a Relational Database
PDF
Json within a relational database
PDF
MySQL Document Store -- SCaLE 17x Presentation
PPTX
Full Stack Web Development.pptx
PPTX
Local SQLite Database with Node for beginners
Node.js with MySQL.pdf
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
harry presentation
MySQL as a Document Store
Mysql Cookbook Solutions For Database Developers And Administrators 4th Editi...
Mysql Cookbook Solutions For Database Developers And Administrators 4th Editi...
Discover the Power of the NoSQL + SQL with MySQL
Discover The Power of NoSQL + MySQL with MySQL
Based on the materials for this week, create your own unique Datab.docx
Unit IV database intergration with node js
Developing for Node.JS with MySQL and NoSQL
Open Source World June '21 -- JSON Within a Relational Database
Json within a relational database
MySQL Document Store -- SCaLE 17x Presentation
Full Stack Web Development.pptx
Local SQLite Database with Node for beginners
Ad

Recently uploaded (20)

DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
KodekX | Application Modernization Development
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Empathic Computing: Creating Shared Understanding
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Cloud computing and distributed systems.
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Machine learning based COVID-19 study performance prediction
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Review of recent advances in non-invasive hemoglobin estimation
The AUB Centre for AI in Media Proposal.docx
NewMind AI Weekly Chronicles - August'25 Week I
KodekX | Application Modernization Development
Spectral efficient network and resource selection model in 5G networks
Empathic Computing: Creating Shared Understanding
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Encapsulation_ Review paper, used for researhc scholars
Mobile App Security Testing_ A Comprehensive Guide.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Cloud computing and distributed systems.
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Machine learning based COVID-19 study performance prediction
Diabetes mellitus diagnosis method based random forest with bat algorithm
Advanced methodologies resolving dimensionality complications for autism neur...
Chapter 3 Spatial Domain Image Processing.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
“AI and Expert System Decision Support & Business Intelligence Systems”
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Review of recent advances in non-invasive hemoglobin estimation

Node Session - 4

  • 2. You have to install MySQL driver to access a MySQL database with Node.js. Download MySQl module from npm. To download and install the "mysql" module, open the Command Terminal and execute the following:  Ex:- Connection with MySQL npm install mysql
  • 3. Create a js file named "connection.js" having the following code:  connection.js:- Connection with MySQL var mysql = require('mysql'); var con = mysql.createConnection({ host: "localhost", //host address user: "root", // username of mysql password: "12345" //password of mysql }); con.connect(function(err) { if (err) throw err; console.log("Connected!"); });
  • 4. Now run a js file named "connection.js". Now open the command terminal and use the following command:  connection.js:- Connection with MySQL node connection.js
  • 5. INSERT INTO statement is used to insert records in MySQL. Insert Record var insertquery = "insert into tbl_student(id,name,age) values ?"; var values = [ [null, 'abc', 22], [null, 'def', 55] ]; mysql.query(insertquery, [values], function(err, result) { if (err) throw err; console.log('Record inserted'); });
  • 6. The UPDATE command is used to update records in the table. Update Record var sql = "UPDATE tbl_student SET age = 25 WHERE id=1"; con.query(sql, function (err, result) { if (err) throw err; console.log(result.affectedRows + " record(s) updated"); });
  • 7. The DELETE FROM command is used to delete records from the table. Delete Record var sql = "DELETE FROM tbl_student WHERE name = ‘xyz’ "; con.query(sql, function (err, result) { if (err) throw err; console.log("Number of records deleted: " + result.affectedRows); });
  • 8. The SELECT command is used to retrieve data from the table. Select Record var sql = "SELECT * from tbl_student"; con.query(sql, function (err, result) { if (err) throw err; console.log(result); });
  • 9. The DROP TABLE command is used to delete or drop a table. Drop Table var sql = "DROP TABLE tbl_student"; con.query(sql, function (err, result) { if (err) throw err; console.log("Table deleted"); });
  • 10. Session IV completed Address: 403, Venus Benecia, Bodakdev,Ahmedabad – 380053 Reach us : reach@techforceinfotech.com Contact no: +91 (79) 48904529