const mysql = require(
'mysql'
);
const con = mysql.createConnection({
host:
"localhost"
,
user:
"yourusername"
,
password:
"yourpassword"
,
database:
"gfg"
});
con.connect(
function
(err) {
if
(err)
throw
err;
console.log(
"Connected!"
);
const sql1 =
"CREATE TABLE geeksforgeeks "
+
"(id INT AUTO_INCREMENT PRIMARY KEY,"
+
" name VARCHAR(255), address VARCHAR(255))"
;
const sql2 =
"INSERT INTO geeksforgeeks (name, "
+
"address) VALUES ('Company Inc', "
+
"'Highway 37')"
;
const sql3 =
"SELECT * FROM geeksforgeeks "
+
"WHERE address = 'Highway 37'"
;
con.query(sql1,
function
(err, result) {
if
(err)
throw
err;
console.log(
"Table created"
);
});
con.query(sql2,
function
(err, result) {
if
(err)
throw
err;
console.log(
"Insertion Successful"
);
});
con.query(sql3,
function
(err, result) {
if
(err)
throw
err;
console.log(result);
});
});