node 连接数据库并插入数据

const mysql = require('mysql')

const db = mysql.createPool({
  host: '127.0.0.1',
  user: 'root',
  password: 'admin123',
  database: 'node',
})

const user = { username: 'DinFa', password: '123' }

const sql = 'insert into users set ?' //插入

const sql = 'update users  set ? where id = 1' // 更新

const sql = 'delete from users where id = 6'  //删除数据

db.query(sql, user, (err, res) => {
  if (err) return console.log(err.message)
  if(res.affectedRows == 1){
    console.log('插入输入成功');
    
  }
  console.log('res', res)
})

你可能感兴趣的:(数据库,mysql,javascript,node.js)