1 //http://www.cnblogs.com/whoamme/p/3459071.html
2 var mysql = require('mysql');
3
4 var TEST_DATABASE = 'test';
5 var TEST_TABLE = 'members';
6
7 //创建连接
8 var client = mysql.createConnection({
9 user: 'root',
10 password: 'root',
11 });
12
13 client.connect();
14 client.query("use " + TEST_DATABASE);
15
16 client.query(
17 'SELECT * FROM '+TEST_TABLE+' WHERE 1 limit 10',
18 function selectCb(err, results, fields) {
19 if (err) {
20 throw err;
21 }
22
23 if(results)
24 {
25 for(var i = 0; i < results.length; i++)
26 {
27 console.log("%d\t%s\t%s", results[i].id, results[i].nickname, results[i].mobile);
28 }
29 }
30 client.end();
31 }
32 );