//引入mysql模块
const mysql = require("mysql");
//创建数据库实例
const connection = mysql.createConnection({
host: "localhost",
user: "root",
password: 'tudengdaji.',
database: "nodeJs"
})
//连接数据库
connection.connect();
//增
connection.query('insert into stu values (null,"大妹",19,"男",default)', function (error, results, field) {
if (error) throw error;
console.log(results);
})
//删
connection.query('delete from stu where id =6', function (error, results, field) {
if (error) throw error;
console.log(results);
})
//改
connection.query('update stu set name ="王哥哥" where id =1', function (error, results, field) {
if (error) throw error;
console.log(results);
})
//查
connection.query('select * from stu', function (error, results, field) {
if (error) throw error;
console.log(results);
})
connection.end();