본문으로 바로가기

 

node로 mariadb 연결

npm install --save mariadb
var maria = require('mariadb');
var client = maria.createConnection({
    host: 'localhost',
    post: 3306,
    database : "nata",
    user : "",
    password : ""
});

//client.connect();
client.query('USE nata');
client.query('select * from t_user', function (err, rows, fields) {
    client.end();
    if(err) {
        console.log('query err');
    }else {
        console.log(rows)
    }
})
client.query('USE nata');
       ^

TypeError: client.query is not a function
    at Object.<anonymous> (/Users/tjpark/Documents/git/nata/node_practice/maria.js:11:8)
    at Module._compile (internal/modules/cjs/loader.js:1200:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
    at Module.load (internal/modules/cjs/loader.js:1049:32)
    at Function.Module._load (internal/modules/cjs/loader.js:937:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47

 

해당 모듈은 제대로 지원하지 않는 것 같다.

 

npm install --save mysql
var maria = require('mysql');
var client = maria.createConnection({
    host: 'localhost',
    post: 3306,
    database : "nata",
    user : "",
    password : ""
});

//client.connect();
client.query('USE nata');
client.query('select * from t_user', function (err, rows, fields) {
    client.end();
    if(err) {
        console.log('query err');
    }else {
        console.log(rows)
    }
})

 

 

정상적으로 출력...

 

현재 버전...

"dependencies": {
    "body-parser": "^1.19.0",
    "connect-multiparty": "^2.2.0",
    "cookie-parser": "^1.4.5",
    "express": "^4.17.1",
    "express-session": "^1.17.1",
    "forever": "^3.0.0",
    "mariadb": "^2.4.0",
    "morgan": "^1.10.0",
    "mysql": "^2.18.1",
    "supervisor": "^0.12.0"
  }