node连接Mysql
下载mysql包
npm i mysql
代码样式
var mysql = require('mysql')
//1.创建连接
var connection = mysql.createConnection({
host:'localhost',
user:'me',
password:'secret',
database:'my_db'
})
connection.connect()
connection.query('sql语句',function(error,results,fields){
if(err) throw error
console.log('the solution is',results[0].solution)
})
connection.end()