mysql模块的作用
mysql模块是一个第三方模块,专门用来操作mysql数据库看,可以执行增删改查操作
npm i mysql
mysql模块的使用步骤
//1.加载mysql const mysql = require("mysql"); //2.创建mysql连接对象,配置项 const conn = mysql.createConnection({ host: "localhost", port: "3306", user: "root", password: "root", database: "user", }); //3.连接mysql服务器 conn.connect(); //4.执行sql语句 conn.query("select * from stu", (err, res) => { console.log(res); }); //5.关闭连接 conn.end();