插入:
const mysql = require('mysql')
const con = mysql.createConnection({
host:'localhost',
user:'root',
password:'root',
port:3306,
database:'myblog'
})
con.connect()
let sql = `insert into blogs (title,content,createtime,author) values ('title1','content1',1607219354313,'dean');`
con.query(sql,(err,data)=>{
if(err){
console.error(err)
}
console.log(data)
})
查询:
let sql = `select * from blogs;`
修改:
let sql = `update blogs set title='my title1' where author='dean'`
删除
let sql = `delete from blogs where title='my title1'`
只有update操作返回的结果里changedRows:1