博客
关于我
node系列:连接mysql数据库
阅读量:289 次
发布时间:2019-03-01

本文共 489 字,大约阅读时间需要 1 分钟。

第一步

在 Node.js 项目中搜索 MySQL,因为这里搜到的都是 Node 的包,找到合适的就是啦。

第二步

安装: 使用命令: ```bash npm install mysql ```

使用:

创建连接:

var mysql = require('mysql');  var connection = mysql.createConnection({      host: 'localhost',      user: 'root',      password: 'root',      database: 'users'  });  connection.connect();

执行数据操作:

connection.query('SELECT * FROM `users`', function (error, results, fields) {      if (error) throw error;      console.log('The solution is: ', results);  });

关闭连接:

connection.end();

转载地址:http://qipo.baihongyu.com/

你可能感兴趣的文章
Now trying to drop the old temporary tablespace, the session hangs.
查看>>
nowcoder—Beauty of Trees
查看>>
np.arange()和np.linspace()绘制logistic回归图像时得到不同的结果?
查看>>
np.power的使用
查看>>
NPM 2FA双重认证的设置方法
查看>>
npm build报错Cannot find module ‘html-webpack-plugin‘解决方法
查看>>
npm build报错Cannot find module ‘webpack/lib/rules/BasicEffectRulePlugin‘解决方法
查看>>
npm build报错Cannot find module ‘webpack‘解决方法
查看>>