과거 프로그래밍 자료들/Javascript&typescript
[JS - node.js] Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client 해결
평부
2021. 12. 20. 15:11
* 윈도우 기준
* vs code 내 node.js와 mysql 연동 중 문제 해결 방법 설명
* mysql workbench 사용
* mysql workbench 설치 및 workbench 내부에 스키마 및 테이블 생성 등 예제 자세히 설명
(https://m.blog.naver.com/tipsware/221304314735)
* 문제 해결 시 참고한 블로그들
(https://1mini2.tistory.com/88)
(https://iflue.tistory.com/141)
[오류 모습]
1
2
3
4
5
6
7
8
|
Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
at Handshake.Sequence._packetToError
code: 'ER_NOT_SUPPORTED_AUTH_MODE',
errno: 1251,
sqlMessage: 'Client does not support authentication protocol requested by server; consider upgrading MySQL client',
sqlState: '08004',
fatal: true
|
cs |
[무엇이 문제?]
클라이언트 프로그램에서 mysql 패스워드 플러그인 "caching_sha2_password"을 소화하지 못해서 생기는 오류
[해결방법 - mysql]
1
2
3
4
5
6
|
ALTER USER '본인 mysql 아이디 '@'본인 mysql localhost'
IDENTIFIED WITH mysql_native_password BY '본인 mysql 비밀번호';
#만약 아이디가 root, 주소가 localhost, 비밀번호가 12345678인 경우
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '12345678';
|
cs |
[해결방법 - mysql 해결 후 vs code]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
port: '3306',
user : 'root',
password : '12345678',
database : 'test' //msql workbench에서 본인이 생성한 스키마 이름
});
connection.connect();
connection.query('SELECT * FROM products', function(err, results, fields) {
if (err) {
console.log(err);
}
console.log(results);
});
connection.end();
|
cs |
출력 부근(안 보이면 ctrl + `(자판 1번 왼쪽 껄 ctrl 누르면 나옴))에서 ctrl + alt + n 눌러 출력하기
혹은 터미널에서 $node js파일이 있는 위치/data_connect.js 입력
(저는 예시 파일 이름이 data_connect.js라서 이렇게 입력
파일 이름이 test.js이고 폴더 이름이 mysql인 경우 : $node mysql/test.js로 입력)
-> 정상적으로 결과 출력
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
[
RowDataPacket {
id: 1,
name: 'Eric Calpton Stratocaster',
modelnumber: '0117602806',
series: 'Artist'
},
RowDataPacket {
id: 2,
name: 'Jeff Beck Stratocaster',
modelnumber: '0119600805',
series: 'Artist'
},
RowDataPacket {
id: 3,
name: 'American Deluxe Stratocaster',
modelnumber: '011900',
series: 'American Deluxe'
},
RowDataPacket {
id: 4,
name: 'American Deluxe Tele',
modelnumber: '011950',
series: 'American Deluxe'
}
]
|
cs |