nodejs mysql
来源:互联网 发布:昭通市2017旅游数据 编辑:程序博客网 时间:2024/06/06 04:16
安装
npm install mysql
实例
http://www.neekey.net/wiki/doku.php?id=nodejs:nodejs%E4%B8%8Emysql
下面以ubuntu下为例
- 安装mysql module
$ npm install mysql
- 新建一个文件 mysql.js
- 输入如下内容
var Client = require('mysql').Client, client = new Client(); client.password = 'helloworld';client.user = 'root'; var DATABASE_NAME = 'neekey_database',TABLE_NAME = 'neekey_table'; console.log(client.connect()); client.query('CREATE DATABASE '+ DATABASE_NAME, function(err) { if (err && err.number != Client.ERROR_DB_CREATE_EXISTS) { console.log(err); throw err; } }); // If no callback is provided, any errors will be emitted as `'error'` // events by the client client.query('USE '+ DATABASE_NAME); client.query( 'CREATE TABLE '+ TABLE_NAME + '(id INT(11) AUTO_INCREMENT, '+ 'title VARCHAR(255), '+ 'text TEXT, '+ 'created DATETIME, '+ 'PRIMARY KEY (id))' ); client.query( 'INSERT INTO '+ TABLE_NAME +' '+ 'SET title = ?, text = ?, created = ?', ['super cool', 'this is a nice text', '2010-08-16 10:00:23'] ); var query = client.query( 'INSERT INTO '+ TABLE_NAME +' '+ 'SET title = ?, text = ?, created = ?', ['another entry', 'because 2 entries make a better test', '2010-08-16 12:42:15'] ); client.query( 'SELECT * FROM '+ TABLE_NAME, function selectCb(err, results, fields) { if (err) { throw err; } console.log(results); console.log(fields); client.end(); } );
- 然后运行该文件
node mysql.js
- nodejs mysql
- nodejs mysql
- Nodejs+MySQL
- nodejs+mysql
- nodejs - mysql操作示例
- Nodejs使用mysql
- nodejs 连接mysql
- nodejs中mysql用法
- nodejs -> mysql - 1
- nodejs中mysql用法
- NodeJs连接Mysql数据库
- 用Nodejs连接MySQL
- nodejs 连接 mysql
- NodeJS连接MySQL
- nodejs连接mysql
- nodejs 与mysql 交互
- nodejs中mysql用法
- nodejs中mysql用法
- 最好的HTML 5编码教程和参考手册分享
- 人生感悟:这九句话不要对父母说
- 单链表
- 用windows api 计算文件的md5值
- Linux下Jboss启动、关闭、端口配置等常见问题FAQ
- nodejs mysql
- Filter之间Pin的连接过程
- C#动态求圆的面积
- jQuery学习《四》
- vc调用matlab生成的C++dll库总结。
- 基于DirectShow的WinCE多媒体编程
- MySql安装
- 使用SQL Server的存储过程和触发器来实时同步ERP和淘宝网的数据
- Android屏幕方向切换时的相关问题