Nodejs的mysql模块学习(一)
介绍
mysql npm包 是一个nodejs的模块,由JavaScript编写
安装
npm install mysql
建立连接
var mysql = require('mysql');//引用Mysql
var connection = mysql.createConnection({//配置连接
host: 'localhost',//数据库地址
user : "user",//数据库用户
password: "password",..//数据库密码
database : "database"//需要连接的数据库
});
connection.connect();//连接数据库
connection.query('select ! + 1 AS solution',function(err,rows,fields){//执行sql语句
if(err) throw err ;
console.log('thesolution is:' rows[0].solution);
});
connection.end();//断开连接
Nodejs的mysql模块学习(一)的更多相关文章
- nodejs的mysql模块学习(二)连接数据库
nodejs连接mysql的方式有两种 官方建议的第一种是 let mysql = require('mysql'); let connection = mysql.createConnection( ...
- nodejs的mysql模块学习(十)连接池集群配置选项
连接池集群选项 canRetry : 如果true ,连接池集群会在连接失败时尝试连接 默认true removeNodeErrorCount : 如果连接失败,节点的errCount增加.当erro ...
- nodejs的mysql模块学习(九)连接池集群
连接池集群 连接池集群可以提供多个主机连接 创建连接池集群 //创建连接池集群 var poolCluster = mysql.createPoolCluster(); //添加配置 config是一 ...
- nodejs的mysql模块学习(六)连接池的创建和使用
介绍 在 软件工程 , 连接池 是一个 高速缓存 的 数据库连接 维持,使得连接可以当需要将来向数据库请求重复使用. [ 来源请求 ] 连接池用于提高数据库上执行命令的性能. 打开并保持每个用户的数据 ...
- nodejs的mysql模块学习(五)数据库连接配置之SSL
SSL选项 在SSL连接选项中需要一个字符串 或者对象 当是字符串的时候 将使用预定义的SSL配置文件 "Amazon RDS" 只有这一个预定义配置文件 用来连接到亚马逊RDS服 ...
- nodejs的mysql模块学习(三)数据库连接配置选项详解
连接选项 当在创建数据连接的时候 第一种大多数人用的方法 let mysql = require('mysql'); let connection = mysql.createConnection({ ...
- nodejs的mysql模块学习笔记(结合业务)
1. 包官网地址 https://www.npmjs.com/package/mysql#install https://www.oschina.net/translate/node-mysql-tu ...
- nodejs的mysql模块学习(八)关闭连接池
关闭连接池 可以用pool.end()关闭连接池 pool.end(function (err) { // 所有的连接都已经被关闭 }); 当关闭之后pool将不可以getconnection()
- nodejs的mysql模块学习(七)连接池事件
连接池事件 connection 当建立连接的时候就会触发 pool.on('connection' function(connection){ connection.query('SET SESSI ...
随机推荐
- Struts2 文件上传
一:表单准备 ① 要想使用HTML 表单上传一个或多个文件 –须把 HTML表单的 enctype属性设置为multipart/form-data –须把HTML 表单的method ...
- Web Service学习之九:Restful WebService
1.Rest 2.Rest webService 3.SpringMVC Restful 参考: http://spring.io/guides/gs/rest-service/ http://www ...
- struts2+Hibernate4+spring3+EasyUI环境搭建之二:搭建spring
三.搭建spring3 1.引入spring3依赖 <!-- spring3 --> <dependency> <groupId>org.springframewo ...
- Spring AOP + AspectJ in XML configuration example
For those don't like annotation or using JDK 1.4, you can use AspectJ in XML based instead. Review l ...
- WEB开发框架
- [转]directsound抓取麦克风PCM数据封装类
网上有很多方法从麦克风读取PCM数据,不想一一举例.只是在这里发布一个我自己写的directsound的麦克风PCM数据采集类,通过它,可以很方便的利用directsound技术把麦克风的数据采集到, ...
- HDU 1828 Picture (线段树+扫描线)(周长并)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1828 给你n个矩形,让你求出总的周长. 类似面积并,面积并是扫描一次,周长并是扫描了两次,x轴一次,y ...
- OS X Git连接github
1. 运行到.local 2. cd ~/.ssh查看文件是否存在 3. ssh-keygen(创建public & private key) 4. 或者运行如下命令:cd ~/.ssh &a ...
- Redis学习_01 windows下的环境搭建
一.Redis 简介 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset( ...
- maven for eclipse在线安装
在线安装 地址变了下面的: http://download.eclipse.org/technology/m2e/releases Eclipse Indigo安装Maven插件Maven ...