学习Nodejs之mysql

学习Nodejs连接mysql数据库:

1、先安装mysql数据库

  

npm install mysql

2、测试连接数据库:

var sql = require("mysql");
var db = sql.createConnection({host:"localhost",ure:"root",password:"",database:"test"});
db.query("select * from user where 1",function(err,data){
    if(err)
        console.log("出错了!");
    else{
        console.log(data+"哈哈");//正确的时候,查询出来的数据data
    }
});

 

posted @ 2014-11-25 00:02  泡沫幻想  阅读(334)  评论(0编辑  收藏  举报