Node操作Mysql的简单例子
先装包
npm install mysql
简单的例子
var mysql = require('mysql') //创建连接 var connection = mysql.createConnection({ host:'localhost', user:'root', password:'08186912', database:'idea' //要连接的数据库名称 }); //连接数据库 connection.connect(); //执行操作 connection.query('SELECT * from users',function(error,results,fields) { if(error) throw error; console.log('结果',fields); console.log('结果',results[0].username); }) //关闭连接 connection.end()