nodejs操作mysql

时间:2021-09-23 07:59:00

var mysql = require('mysql');
var pool = mysql.createPool({
host: 'localhost',
user: 'root',
password: '',
database: 'nodejs',
port: 3306
});

var selectSQL ="show variables like 'wait_timeout'";

pool.getConnection(function (err, conn) {
if (err) console.log("POOL ==> " + err);

function query(){
conn.query(selectSQL, function (err, res) {
console.log(new Date());
console.log(res);
//conn.release();
});
}
query();
query();
query();
query();

//setInterval(query, 1000);
});