에러 해결) ER_NOT_SUPPORTED_AUTH_MODE : Node.js에서 MySQL을 접근할 때 발생하는 에러
* 에러 해결 - 증상 *
Node.js에서 MySQL을 접근하려고 하니 다음과 같은 오류 발생
에러 내용 :
Error connecting to 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 접속
mysql -u root -p
1. 외부 접속 허용 확인
1) mysql 외부접속 허용이 되어있는지 확인
select host, user from mysql.user;
위와 같이 host에 localhost 이외 주소가 없다면 외부 접속 허용이 불가능한 상황!
2) 사용자 등록 필요
host 주소에 %로 지정해 서버와 같이 외부에서 사용될 수 있도록 해준다
(MySQL에서 %는 와일드카드로 사용됨)
//생성
CREATE USER 'nodejs'@'%' identified by 'ReactNode1!';
//권한 설정
GRANT ALL PRIVILEGES ON *.* to 'nodejs'@'%';
//새로고침
flush privileges;
SELECT Host,User,plugin,authentication_string FROM mysql.user;
2. 비밀번호 플러그인 확인
MySQL 8.0에서는 MySQL 패스워드 플러그인 "caching_sha2_password" 때문에 에러가 발생하기도 한다
1) 현재 플러그인 확인
select host, user, plugin, authentication_string from mysql.user;
2) 플러그인 바꾸기
> mysql_native_password 플러그인으로 변경
ALTER USER 'nodejs'@'%' IDENTIFIED WITH mysql_native_password BY 'ReactNode1!';
최종 확인
select host, user, plugin, authentication_string from mysql.user;