var mysql = require("mysql"); var connection = mysql.createConnection({ host: ‘127.0.0.1‘, user: "root", //数据库用户名 password: "12345", //数据库密码 database: "test", //数据库 port: ‘3306‘ //端口号 }); connection.connect(function(err){ if(err){ console.log(‘[连接失败] - :‘+err); return; } }); connection.query(‘SELECT * FROM `mall`‘, function (error, rows, fields) { if(!error) { console.log(JSON.stringify(rows)); } }); //关闭连接 connection.end();
node.js 连接 mysql,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/langlang/p/3844710.html