[Node.js]외부 실행 모듈 - mysql
■ mysql
node.js 에서 mysql을 사용하고자 하는 경우 아래의 모듈을 활용한다.
- 사이트
https://github.com/felixge/node-mysql- npm을 통한 설치
npm install mysql
- 설명
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:
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.