node.js - 2
2019.09.27 09:28
Node.js MySQL
조회 수 315 추천 수 0 댓글 0
MySQL Driver 설치
C:\Users\Your Name>npm install mysql
MySQL 사용을 위해 아래와 같이 드라이버를 로드한다.
var mysql = require('mysql');
Create Connection
var mysql = require('mysql'); var con = mysql.createConnection({ host: "localhost", user: "yourusername", password: "yourpassword" }); con.connect(function(err) { if (err) throw err; console.log("Connected!"); });
C:\Users\Your Name>node dbConnection.js
Query a Database
con.connect(function(err) { if (err) throw err; console.log("Connected!"); con.query(sql, function (err, result) { if (err) throw err; console.log("Result: " + result); }); });
Creating a Database
var mysql = require('mysql'); var con = mysql.createConnection({ host: "localhost", user: "yourusername", password: "yourpassword" }); con.connect(function(err) { if (err) throw err; console.log("Connected!"); con.query("CREATE DATABASE mydb", function (err, result) { if (err) throw err; console.log("Database created"); }); });
번호 | 분류 | 제목 | 날짜 | 조회 수 |
---|---|---|---|---|
38 | node.js - 1 | Express에서 POST 방식 사용하기 | 2019.10.16 | 349 |
37 | node.js - 1 | Express에서 MySql 사용 | 2019.10.10 | 843 |
36 | node.js - 2 | Node.js MySQL Limit | 2019.10.10 | 288 |
35 | node.js - 2 | Node.js MySQL Update | 2019.10.10 | 276 |
34 | node.js - 2 | Node.js MySQL Drop Table | 2019.10.08 | 357 |
33 | node.js - 2 | Node.js MySQL Delete | 2019.10.08 | 302 |
32 | node.js - 2 | Node.js MySQL Order By | 2019.10.08 | 285 |
31 | node.js - 2 | Node.js MySQL Where | 2019.10.08 | 494 |
30 | node.js - 2 | Node.js MySQL Select From | 2019.10.08 | 630 |
29 | node.js - 2 | Node.js MySQL Insert Into | 2019.10.01 | 933 |
28 | node.js - 2 | Node.js MySQL Create Table | 2019.10.01 | 324 |
27 | PUG | PUG 07 / INCLUDES | 2019.10.01 | 358 |
26 | PUG | PUG 06 / DOCTYPE | 2019.10.01 | 431 |
» | node.js - 2 | Node.js MySQL | 2019.09.27 | 315 |
24 | node.js - 2 | NPM의 사용 | 2019.09.26 | 313 |
23 | node.js - 2 | Node.js URL Module | 2019.09.26 | 461 |
22 | PUG | PUG 05 / Conditionals | 2019.09.19 | 755 |
21 | PUG | PUG 04 / Comments | 2019.09.19 | 329 |
20 | PUG | PUG 03 / Code | 2019.09.19 | 691 |
19 | PUG | PUG 02 / Case | 2019.09.19 | 367 |