demo_db_delete.js:
var mysql = require('mysql'); var con = mysql.createConnection({ host: "localhost", user: "myusername", password: "mypassword", database: "mydb" }); con.connect(function(err) { if (err) throw err; //Delete all customers with the address "Mountain 21": var sql = "DELETE FROM customers WHERE address = 'Mountain 21'"; con.query(sql, function (err, result) { if (err) throw err; console.log("Number of records deleted: " + result.affectedRows); }); });
C:\Users\My Name>node demo_db_delete.js
Number of records deleted: 1