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

你可能感兴趣的文章
Python 数据库骚操作 -- MySQL
查看>>
Python 数据操作详解
查看>>
Python 数据文件与网络数据序列化存储详解
查看>>
Python 数据结构与算法详解
查看>>
Python 数据采集、清洗、整理、分析以及可视化实战
查看>>
Python 数据预处理
查看>>
python 文件类型检测 linux和windows都可以用
查看>>
Python多处理池,加入;不等待继续?
查看>>
Python多处理帮助在条件下退出
查看>>
Python 无法安装包
查看>>
python 日历小部件 - 返回用户选择的日期
查看>>
Python 日志管理封装
查看>>
python 时间函数小总结
查看>>
Python 是否优化尾递归?
查看>>
Python 更新set
查看>>
Python 最强 IDE 详细使用指南!
查看>>
Python 有一个不可变的列表吗?
查看>>
Python 机器学习入门之 pandas 的使用
查看>>
Python 机器学习实战
查看>>
python 杀死子进程_subprocess.popen.kill杀死所有子进程
查看>>