1 | npm install -g mysql |
node中使用Mysql模块来执行mysql命令
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | var http = require( "http" ), mysql = require( "mysql" ); var connection = mysql.createConnection({ user: "root" , //数据库用户名 password: "1234" , //数据库密码 database: "nodejs" //数据库 }); http.createServer( function (request, response) { connection.query( 'select * from hg_admin;' , function (error, rows, fields) { response.writeHead( 200 , { "Content-Type" : "text/plain" }); response.end(JSON.stringify(rows)); }); }).listen( 8080 ); |