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

你可能感兴趣的文章
NFinal学习笔记 02—NFinalBuild
查看>>
NFS
查看>>
NFS Server及Client配置与挂载详解
查看>>
NFS共享文件系统搭建
查看>>
nfs复习
查看>>
NFS安装配置
查看>>
NFS的安装以及windows/linux挂载linux网络文件系统NFS
查看>>
NFS的常用挂载参数
查看>>
NFS网络文件系统
查看>>
nft文件传输_利用remoting实现文件传输-.NET教程,远程及网络应用
查看>>
NFV商用可行新华三vBRAS方案实践验证
查看>>
ng build --aot --prod生成文件报错
查看>>
ng 指令的自定义、使用
查看>>
nghttp3使用指南
查看>>
Nginx
查看>>
nginx + etcd 动态负载均衡实践(三)—— 基于nginx-upsync-module实现
查看>>
nginx + etcd 动态负载均衡实践(二)—— 组件安装
查看>>
nginx + etcd 动态负载均衡实践(四)—— 基于confd实现
查看>>
Nginx + Spring Boot 实现负载均衡
查看>>
Nginx + uWSGI + Flask + Vhost
查看>>