首先使用npm install mysql
代码语言:javascript复制var mysql = require('mysql');
var conn = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '123456',
database: 'mysql',
port: 3306
});
conn.connect();
conn.query(
'select * from user',
function (err, res, fields) {
if (err) throw err;
for (
var i = 0;
i < res.length;
i
) {
var obj = res[i];
console.log(obj);
}
}
);
conn.end();