我们可以使用以下代码来删除 id 为 6 的数据:
删除数据
var mysql = require('mysql'); var connection = mysql.createConnection({ host : 'localhost', user : 'root', password : '123456', port: '3306', database: 'test' }); connection.connect(); var delSql = 'DELETE FROM websites where id=6';//删connection.query(delSql,function (err, result) { if(err){ console.log('[DELETE ERROR] - ',err.message); return; } console.log('--------------------------DELETE----------------------------'); console.log('DELETE affectedRows',result.affectedRows); console.log('-----------------------------------------------------------------\n\n'); }); connection.end();
执行以下命令输出就结果为:
--------------------------DELETE----------------------------
DELETE affectedRows 1
-----------------------------------------------------------------
执行成功后,查看数据表,即可以看到 id=6 的数据已被删除: