[MySQL] Nodejs 연동 시 에러 Client does not support authentication...

Stylish·2023년 6월 12일
0
post-thumbnail

nodejs에 mysql을 연동하려니 갑자기 에러를 뱉는다..ㅠ

1. 사용한 코드

// index.js
const mysql = require('mysql') // mysql 모듈 로드
const connection = mysql.createConnection({
  // mysql 접속 설정
  host: '127.0.0.1', //   host: 'localhost',
  port: '3306',
  user: 'root',
  password: 'test123',
  database: 'my_db',
})

connection.connect()

connection.query('SELECT * from users', (error, rows, fields) => {
  if (error) throw error
  console.log('user info is: ', rows)
})

connection.end()

2. 에러

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

3. 해결

mysql client에서 mysql 패스워드 플러그인 "caching_sha2_password"로 인해 발생하는 오류.
플러그인을 바꿔주면 해결!
sql에서 아래와 같이 넣어주면 해결!

ALTER USER '[MYSQL 아이디]'@'[MYSQL 주소]' IDENTIFIED WITH mysql_native_password BY '[MYSQL 비밀번호]';

나의 경우에는 아래와 같이 입력해서 해결했다.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
profile
까먹지 않기 위해 기록하는 개발자

0개의 댓글