1. 程式人生 > >nodejs mysql 創建連接池

nodejs mysql 創建連接池

寫代碼 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 創建連接池