标签:connect creat nec 关闭 console nod user sel database
创建db.js
1.安装mysql依赖
//打开终端,输入 npm install mysql
2.导入mysql依赖
var mysql = require(‘mysql‘);
3.创建一个mysql的Connection对象,配置数据库连接信息。
var conntion = mysql.createConnection({ host:"127.0.0.1", port:3306, user:‘root‘, password:‘123456‘, database:‘testdb‘ });
4.开辟连接
connection.connect();
5.运行 crud
connection.query(‘select * from kss_user‘,function(error,results,fields){ if(error) throw error; console.log(‘results = ‘,results); });
6.关闭连接
connection.end();
7.打开终端输入 node db.js
标签:connect creat nec 关闭 console nod user sel database
原文地址:https://www.cnblogs.com/nyfq/p/14578633.html