Node.js | MySQL 연동
※ 현재 사용하고 있는 MySQL의 버전은 8.0.18버전으로, MySQL과 연동할 때 오류가 발생할 수 있다.
이유는 이전 버전과 최신 버전의 비밀번호 형식이 변경되어서 라고 하는데... 아래 링크를 참고하면 해결 가능하다.
MySQL 8.0 - Client does not support authentication protocol requested by server; consider upgrading MySQL client
I am a node.js and MySQL beginner and I just started setting up and trying out some basic code. However, I can't make even a simple connection to the server for some reason. I install the newest My...
stackoverflow.com
Node.js can't authenticate to MySQL 8.0
I have a Node.js program that connects to a local MySQL database with the root account (this is not a production setup). This is the code that creates the connection: const mysql = require('mysql'...
stackoverflow.com
1. MySQL 모듈 설치
$ npm install --save mysql
2. MySQL과 연결(Connection)
host, user, password, database를 정확히 적으면 성공적으로 연결이 될 것이다.
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'me',
password : 'secret',
database : 'my_db'
});
connection.connect();
connection.query('SELECT 1 + 1 AS solution', function (error, results, fields) {
if (error) throw error;
console.log('The solution is: ', results[0].solution);
});
connection.end();
3. 연결 확인
+) 참고
mysql
A node.js driver for mysql. It is written in JavaScript, does not require compiling, and is 100% MIT licensed.
www.npmjs.com