博客
关于我
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/

你可能感兴趣的文章
prometheus监控docker容器实战
查看>>
Prometheus监控k8s集群使用邮箱和微信告警!
查看>>
Prometheus监控mysq数据库实战
查看>>
prometheus监控nginx实战
查看>>
Prometheus监控redis数据库实战
查看>>
Prometheus监控教程:使用Grafana展示主机基本信息
查看>>
pytorch中如何使用预训练词向量
查看>>
Prometheus监控教程:使用PromQL查询监控数据(上篇)
查看>>
Prometheus监控教程:使用PromQL查询监控数据(下篇)
查看>>
Pytorch中关于forward函数的理解与用法
查看>>
Prometheus监控教程:安装部署
查看>>
Prometheus监控教程:配置介绍
查看>>
Pytorch中tqdm进度条的使用
查看>>
Prometheus(2):SpringBoot 2.X集成Prometheus
查看>>