nodejs mysql 創建連接池
阿新 • • 發佈:2017-11-14
寫代碼 getc local .cn user 查詢 password sql node
1.設計數據庫
2.編寫代碼
demo
var mysql = require(‘mysql‘); var pool = mysql.createPool({ host : ‘localhost‘, port : ‘3300‘, database : ‘user‘, user : ‘root‘, password : ‘123456‘, }); pool.getConnection(function(err, connection) { if(err) console.log(‘MySQL數據庫建立連接失敗。‘);else{ console.log(‘數據庫建立連接成功。‘); connection.query( ‘select * from user‘, function(err, data) { if(err) console.log(‘查詢數據操作失敗。‘); else{ console.log(data); pool.end(); } }); } });
3.輸出效果:
nodejs mysql 創建連接池