1. 설치
npm install --save mysql2
2. Promise Wrapper 사용
async () => {
// get the client
const mysql = require('mysql2');
// create the pool
const pool = mysql.createPool({host:'localhost', user: 'root', database: 'test'});
// now get a Promise wrapped instance of that pool
const promisePool = pool.promise();
// query database using promises
const [rows,fields] = await promisePool.query("SELECT 1");
pool.end();
}'컴퓨터 > NodeJS' 카테고리의 다른 글
| NodeJS crypto 암호화 복호화 (0) | 2022.07.25 |
|---|---|
| NodeJS cors (0) | 2022.07.06 |
| NodeJS networkInterfaces 로컬 네트워크 정보 (0) | 2022.05.14 |
| npm xml-js (0) | 2022.05.02 |
| GITHUB (0) | 2022.04.01 |