# mysql
[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
[![Node.js Version][node-version-image]][node-version-url]
[![Build Status][travis-image]][travis-url]
[![Test Coverage][coveralls-image]][coveralls-url]
## Install
```sh
$ npm install mysql
```
For information about the previous 0.9.x releases, visit the [v0.9 branch][].
Sometimes I may also ask you to install the latest version from Github to check
if a bugfix is working. In this case, please do:
```sh
$ npm install felixge/node-mysql
```
[v0.9 branch]: https://github.com/felixge/node-mysql/tree/v0.9
## Introduction
This is a node.js driver for mysql. It is written in JavaScript, does not
require compiling, and is 100% MIT licensed.
Here is an example on how to use it:
```js
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'me',
password : 'secret'
});
connection.connect();
connection.query('SELECT 1 + 1 AS solution', function(err, rows, fields) {
if (err) throw err;
console.log('The solution is: ', rows[0].solution);
});
connection.end();
```
From this example, you can learn the following:
* Every method you invoke on a connection is queued and executed in sequence.
* Closing the connection is done using `end()` which makes sure all remaining
queries are executed before sending a quit packet to the mysql server.
## Contributors
Thanks goes to the people who have contributed code to this module, see the
[GitHub Contributors page][].
[GitHub Contributors page]: https://github.com/felixge/node-mysql/graphs/contributors
Additionally I'd like to thank the following people:
* [Andrey Hristov][] (Oracle) - for helping me with protocol questions.
* [Ulf Wendel][] (Oracle) - for helping me with protocol questions.
[Ulf Wendel]: http://blog.ulf-wendel.de/
[Andrey Hristov]: http://andrey.hristov.com/
## Sponsors
The following companies have supported this project financially, allowing me to
spend more time on it (ordered by time of contribution):
* [Transloadit](http://transloadit.com) (my startup, we do file uploading &
video encoding as a service, check it out)
* [Joyent](http://www.joyent.com/)
* [pinkbike.com](http://pinkbike.com/)
* [Holiday Extras](http://www.holidayextras.co.uk/) (they are [hiring](http://join.holidayextras.co.uk/vacancy/software-engineer/))
* [Newscope](http://newscope.com/) (they are [hiring](http://www.newscope.com/stellenangebote))
If you are interested in sponsoring a day or more of my time, please
[get in touch][].
[get in touch]: http://felixge.de/#consulting
## Community
If you'd like to discuss this module, or ask questions about it, please use one
of the following:
* **Mailing list**: https://groups.google.com/forum/#!forum/node-mysql
* **IRC Channel**: #node.js (on freenode.net, I pay attention to any message
including the term `mysql`)
## Establishing connections
The recommended way to establish a connection is this:
```js
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'example.org',
user : 'bob',
password : 'secret'
});
connection.connect(function(err) {
if (err) {
console.error('error connecting: ' + err.stack);
return;
}
console.log('connected as id ' + connection.threadId);
});
```
However, a connection can also be implicitly established by invoking a query:
```js
var mysql = require('mysql');
var connection = mysql.createConnection(...);
connection.query('SELECT 1', function(err, rows) {
// connected! (unless `err` is set)
});
```
Depending on how you like to handle your errors, either method may be
appropriate. Any type of connection error (handshake or network) is considered
a fatal error, see the [Error Handling](#error-handling) section for more
information.
## Connection options
When establishing a connection, you can set the following options:
* `host`: The hostname of the database you are connecting to. (Default:
`localhost`)
* `port`: The port number to connect to. (Default: `3306`)
* `localAddress`: The source IP address to use for TCP connection. (Optional)
* `socketPath`: The path to a unix domain socket to connect to. When used `host`
and `port` are ignored.
* `user`: The MySQL user to authenticate as.
* `password`: The password of that MySQL user.
* `database`: Name of the database to use for this connection (Optional).
* `charset`: The charset for the connection. This is called "collation" in the SQL-level
of MySQL (like `utf8_general_ci`). If a SQL-level charset is specified (like `utf8mb4`)
then the default collation for that charset is used. (Default: `'UTF8_GENERAL_CI'`)
* `timezone`: The timezone used to store local dates. (Default: `'local'`)
* `connectTimeout`: The milliseconds before a timeout occurs during the initial connection
to the MySQL server. (Default: `10000`)
* `stringifyObjects`: Stringify objects instead of converting to values. See
issue [#501](https://github.com/felixge/node-mysql/issues/501). (Default: `'false'`)
* `insecureAuth`: Allow connecting to MySQL instances that ask for the old
(insecure) authentication method. (Default: `false`)
* `typeCast`: Determines if column values should be converted to native
JavaScript types. (Default: `true`)
* `queryFormat`: A custom query format function. See [Custom format](#custom-format).
* `supportBigNumbers`: When dealing with big numbers (BIGINT and DECIMAL columns) in the database,
you should enable this option (Default: `false`).
* `bigNumberStrings`: Enabling both `supportBigNumbers` and `bigNumberStrings` forces big numbers
(BIGINT and DECIMAL columns) to be always returned as JavaScript String objects (Default: `false`).
Enabling `supportBigNumbers` but leaving `bigNumberStrings` disabled will return big numbers as String
objects only when they cannot be accurately represented with [JavaScript Number objects] (http://ecma262-5.com/ELS5_HTML.htm#Section_8.5)
(which happens when they exceed the [-2^53, +2^53] range), otherwise they will be returned as
Number objects. This option is ignored if `supportBigNumbers` is disabled.
* `dateStrings`: Force date types (TIMESTAMP, DATETIME, DATE) to be returned as strings rather then
inflated into JavaScript Date objects. (Default: `false`)
* `debug`: Prints protocol details to stdout. (Default: `false`)
* `trace`: Generates stack traces on `Error` to include call site of library
entrance ("long stack traces"). Slight performance penalty for most calls.
(Default: `true`)
* `multipleStatements`: Allow multiple mysql statements per query. Be careful
with this, it exposes you to SQL injection attacks. (Default: `false`)
* `flags`: List of connection flags to use other than the default ones. It is
also possible to blacklist default ones. For more information, check
[Connection Flags](#connection-flags).
* `ssl`: object with ssl parameters or a string containing name of ssl profile. See [SSL options](#ssl-options).
In addition to passing these options as an object, you can also use a url
string. For example:
```js
var connection = mysql.createConnection('mysql://user:pass@host/db?debug=true&charset=BIG5_CHINESE_CI&timezone=-0700');
```
Note: The query values are first attempted to be parsed as JSON, and if that
fails assumed to be plaintext strings.
### SSL options
The `ssl` option in the connection options takes a string or an object. When given a string,
it uses one of the predefined SSL profiles included. The following profiles are included:
* `"Amazon RDS"`: this profile is for connecting to an Amazon RDS server and contains the
ca from https://rds.amazonaws.com/doc/rds-ssl-ca-cert.pem
When connecting to other servers, you will need to provide an object of options, in the
same format as [crypto.createCredentials](http://nodejs.org/api/crypto.html#crypto_crypto_createcredentials_details).
Please note the arguments expect a string of the certificate, not a file n
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
软件开发设计:应用软件开发、系统软件开发、移动应用开发、网站开发C++、Java、python、web、C#等语言的项目开发与学习资料 硬件与设备:单片机、EDA、proteus、RTOS、包括计算机硬件、服务器、网络设备、存储设备、移动设备等 操作系统:LInux、树莓派、安卓开发、微机操作系统、网络操作系统、分布式操作系统等。此外,还有嵌入式操作系统、智能操作系统等。 网络与通信:数据传输、信号处理、网络协议、网络与通信硬件、网络安全网络与通信是一个非常广泛的领域,它涉及到计算机科学、电子工程、数学等多个学科的知识。 云计算与大数据:包括云计算平台、大数据分析、人工智能、机器学习等,云计算是一种基于互联网的计算方式,通过这种方式,共享的软硬件资源和信息可以按需提供给计算机和其他设备。
资源推荐
资源详情
资源评论
收起资源包目录
这是一个基于Node.js的微博项目,使用mysql数据库 .zip (838个子文件)
no.2js 23B
Cakefile 624B
node-supervisor.cmd 155B
supervisor.cmd 155B
ipaddr.coffee 11KB
ipaddr.test.coffee 10KB
bootstrap.css 134KB
bootstrap.min.css 111KB
bootstrap-theme.css 21KB
bootstrap-theme.min.css 19KB
uploadify.css 3KB
bootstrap-markdown.min.css 3KB
blog.css 2KB
signin.css 824B
style.css 110B
style.css 32B
blogAdd.ejs 2KB
userSet.ejs 2KB
home.ejs 2KB
myhome.ejs 2KB
reg.ejs 1KB
login.ejs 1KB
comments.ejs 324B
menu_preprocessor.ejs 250B
menu.ejs 222B
index.ejs 222B
footer.ejs 187B
menu_var.ejs 183B
include-abspath.ejs 114B
include.ejs 98B
newlines.ejs 89B
no.newlines.ejs 89B
error.ejs 83B
include_preprocessor.ejs 80B
messed.ejs 71B
error.ejs 62B
include_preprocessor.css.ejs 61B
include.css.ejs 60B
consecutive-tags.ejs 47B
include-simple.ejs 44B
double-quote.ejs 40B
item.ejs 38B
fail.ejs 34B
single-quote.ejs 33B
menu-item.ejs 32B
user-no-with.ejs 28B
pet.ejs 25B
user.ejs 21B
hello-world.ejs 20B
para.ejs 10B
backslash.ejs 4B
glyphicons-halflings-regular.eot 20KB
.gitattributes 378B
.gitignore 574B
API.html 56KB
comments.html 135B
menu.html 98B
menu_preprocessor.html 98B
newlines.html 78B
include_preprocessor.html 78B
include.html 78B
no.newlines.html 68B
messed.html 50B
include_preprocessor.css.html 37B
include.css.html 37B
include-simple.html 32B
double-quote.html 26B
single-quote.html 24B
backslash.html 4B
consecutive-tags.html 4B
weBlog.iml 360B
Jakefile 1KB
moment-with-locales.js 341KB
locales.js 268KB
moment-with-locales.min.js 157KB
locales.min.js 136KB
errors.js 124KB
moment.js 97KB
jquery.min.js 94KB
bootstrap.js 64KB
bignumber.js 58KB
markdown.js 58KB
bootstrap-markdown.js 49KB
jquery.uploadify.min.js 45KB
docs.min.js 42KB
moment.min.js 34KB
bootstrap.min.js 34KB
sbcs-data-generated.js 31KB
_stream_readable.js 25KB
ejs.js 24KB
response.js 24KB
dbcs-codec.js 21KB
index.js 16KB
test.js 16KB
index.js 14KB
ejs.js 14KB
ejs.min.js 14KB
index.js 14KB
ejs.js 14KB
parse.js 13KB
共 838 条
- 1
- 2
- 3
- 4
- 5
- 6
- 9
资源评论
妄北y
- 粉丝: 1w+
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- BDD,Python 风格 .zip
- 个人原创STM32F1 BOOTLOADER,主控芯片为STM32F103VET6
- Alpaca 交易 API 的 Python 客户端.zip
- 基于Django与讯飞开放平台的ACGN文化交流平台源码
- 中国象棋(自行初步设计)
- 微信小程序实现找不同游戏
- 100_Numpy_exercises.ipynb
- 2023-04-06-项目笔记 - 第三百二十六阶段 - 4.4.2.324全局变量的作用域-324 -2025.11.23
- 一个简单的模板,开始用 Python 编写你自己的个性化 Discord 机器人.zip
- TP-Link 智能家居产品的 Python API.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功