var mysql = require('mysql'); console.log('======= mysql.createConnection() Start ' + Date.now()) var connection = mysql.createConnection({ host : '127.0.0.1', user : 'root', password : '123456', port: '3306', database: 'dbname', }); console.log('======= mysql.createConnection() Stop ' + Date.now()) console.log('======= connect() Start' + Date.now()) connection.connect(); console.log('======= connect() Stop ' + Date.now()) var userGetSql = 'SELECT 1 + 1 AS a'; console.log('======= query() Start' + Date.now()) connection.query(userGetSql,function (err, result) { if(err){ console.log('[SELECT ERROR] - ',err.message); return; } console.log(result); }); console.log('======= query() Stop ' + Date.now()) connection.end();
npm install mysql
nodejs select.js
转载请注明:爱开源 » NodeJS 连接 mysql