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();