nodejs 连接 mysql
2021-07-29 本文已影响0人
弦生_a3a3
const mysql=require('mysql');
//创建连接对象
const connection=mysql.createConnection({
host:'localhost',
user:'root',
password:'123123',
port:'3306',
database:'admin_demo'
})
//开始连接
connection.connect();
//执行mysql语句
const sql = 'select * from `user`'
connection.query(sql,(err,result)=>{
if(err){
console.log(err)
return;
}
console.log('result',result);
})
//关闭连接
connection.end();