const mysql = require('mysql')
const con = mysql.createConnection({
host: '127.0.0.1',
user: 'root',
password: '123456',
port: '3306',
database: 'myblog',
insecureAuth: true
})
con.connect()
let sql = 'select * from users'
con.query(sql, (err, result) => {
if(err) {
console.log(err)
return
}
console.log(result)
})
con.end()
将nodejs连接数据库做成工具(按照环境区分)