//1、导入模块
const mariadb = require('mariadb');
//2、创建连接池
const pool = mariadb.createPool({
host: 'ip-------',
user: '用户名',
port:3306,
password: '密码',
database:'数据库',
connectionLimit: 5
});
//获取用户查询
function getUserInfo(params) {
pool.getConnection();
.then(conn => {
conn.query("SELECT * from FrontendEntity limit 1")
.then(rows => {
console.log(rows);
conn.release(); // release to pool
})
.catch(err => {
console.log(err);
conn.release(); // release to pool
})
}).catch(err => {
console.log(err);
//not connected
});
}
原文链接 https://www.npmjs.com/package/mariadb