nodeJS에서 MySQL 연결시 ER_NOT_SUPPORTED_AUTH_MODE 에러 해결
개요
node 에서 mysql 로 연결할 경우 다음과 같은 에러가 발생하는 경우가 있습니다.
Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client 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 }
원인
MySQL 8 을 사용할 경우 새로운 인증 정책을 도입해서 기본 인증이 mysql_native_password 에서 caching_sha2_password 로 변경되었습니다.
메시지대로 mysql client 를 업데이트해도 되지만 가장 간단한 방법은 에러나는 계정의 인증 정책을 예전 방식으로 설정하는 것입니다.
ALTER USER lesstif IDENTIFIED WITH mysql_native_password BY 'mypassword';
더 자세한 내용은 MySQL 8 인증 정책(Authentication policy) 수정하기 를 참고하세요