//先下好包 npm install mysql
const {
connect
} = require("http2");
//导包
var mysql = require("mysql");
//创建连接
var connetction = mysql.createConnection({
host: "127.0.0.1",
port: "3306",
user: "root",
password: "123456",
database: "test"
});
//配置数据库连接数据
//开辟连接
connetction.connect();
//执行sql
connetction.query("select * from t1", function (_errro, result, fields) {
if (_errro) throw _errro;
console.log(result);
});
//关闭连接
connetction.end;