一,在没有mysql数据库连接池之前,后端每一次操作数据库都需要创建一个新的connection对象,建立连接,操作,销毁,效率低,性能低,数据库的压力比较大
router.get("/api",(req, res) => {
let config = {
host:"localhost",
user:"root",
password:"root",
database:"web2106"
}
let pool = mysql.createPool(config);
pool.getConnection((err,connection)=>{
connection.query("select * from tb_dept",(error,result)=>{
connection.release();
});
});
res.send("hhh");
});
二,使用MySQL
2.1需要先下载MySQL模块
npm install mysql
2.2引入模块
let mysql = require("mysql");