var mysql = require('mysql');
var TEST_DATABASE = 'msg';
var TEST_TABLE = 'msg';
//创建连接
var client = mysql.createConnection({
user: 'long',
password: '123456',
});
client.connect();
client.query("use " + TEST_DATABASE);
client.query(
'SELECT * FROM '+TEST_TABLE,
function selectCb(err, results, fields) {
if (err) {
throw err;
}
if(results)
{
for(var i = 0; i < results.length; i++)
{
console.log("%d\t%s\t%s", results[i].id, results[i].username, results[i].title);
}
}
client.end();
}
);
/*百度: mysql数据库用navicat新建用户*/
nodejs连接database
最新推荐文章于 2024-06-13 00:09:31 发布