首页 > 代码库 > node js 读取mysql

node js 读取mysql

技术分享

1、新版node自带npm 2、下载npm不需要node命令 3、懒得配环境变量、直接把生成的npm复制到报错目录,再把mysql模块复制回来

技术分享

 

var mysql = require(‘mysql‘);var conn = mysql.createConnection({    host: ‘localhost‘,    user: ‘root‘,    password: ‘root‘,    database:‘nodejs‘,    port: 3306});conn.connect();conn.query(‘SELECT * from fleam‘, function(err, re) {    if (err) {throw err;}else{console.log(re);}    });conn.end();

 

node js 读取mysql