ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
    MySQL 2024. 10. 27. 20:42

    문제 상황

    서버를 실행시키려고 여느 때와 같이 npm run start:dev 를 하는데 두둥 에러가 떴다.

     

    Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client

     

    해당 프로젝트의 서버는 nest.js 와 DB로 MySQL을 사용하고 있었다. Node.js와 MySQL을 연동하는데 문제가 있는 걸로 보였다.

     

    최근에 MySQL을 8 버전대로 업데이트했는데 이게 문제 인 것 같다. 

     

    찾아보니 원래 MySQL의 default_authentication_plugin(기본 인증 플러그인)은 mysql_native_password이었다.

    하지만, MySQL 8부터 보안이 강화된 caching_sha2_password로 변경되면서 문제가 생긴 것이다.

     

    MySQL 클라이언트가 아직 caching_sha2_password 방식을 지원하지 못하는 경우 이런 에러가 발생하게 된다고 한다. 

     

    다시 말해, 이번 문제는 Node.js의 MySQL 모듈이 아직 caching_sha2_password 방식을 지원하지 못해서 생긴 문제다. 인증 플러그인이나 Node.js 와 MySQL 연결 방식을 완전히 알고 있지는 않아서 완벽하게 이해하기는 어렵지만 에러는 해결할 수 있었다. (이후에 자세히 공부해 보고 싶다.)

     

    Node.js의 mySQL 모듈이 지원하는 mysql_native_password 방식으로 바꿔주면 된다.

     

    stackoverflow를 보니 비슷한 문제를 해결한 경우가 있어서 참고했다.

     

    https://stackoverflow.com/questions/50093144/mysql-8-0-client-does-not-support-authentication-protocol-requested-by-server

     

    MySQL 8.0 - Client does not support authentication protocol requested by server; consider upgrading MySQL client

    I can't make a simple connection to the server for some reason. I install the newest MySQL Community 8.0 database along with Node.JS with default settings. This is my node.js code var mysql = r...

    stackoverflow.com

     

     

    문제 해결

     

    우선 프로젝트에서 사용한 MySQL의 유저에 해당하는 플러그인을 한번 확인해 보자.

     

    select host, user, plugin from mysql.user;
    
    mysql> select host, user, plugin from mysql.user;
    +-----------+------------------+-----------------------+
    | host      | user             | plugin                |
    +-----------+------------------+-----------------------+
    | localhost | mysql.infoschema | caching_sha2_password |
    | localhost | mysql.session    | caching_sha2_password |
    | localhost | mysql.sys        | caching_sha2_password |
    | localhost | root             | caching_sha2_password |
    +-----------+------------------+-----------------------+

     

     

    내가 사용할 유저는 root인데 해당 plugin이 caching_sha2_password 방식을 사용하고 있음을 확인할 수 있었다.

     

    이제 root 유저의 plugin의 mysql_native_password 방식으로 바꿔주면 된다. 

     

    mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '비밀번호';
    
    mysql> select host, user, plugin from mysql.user;
    +-----------+------------------+-----------------------+
    | host      | user             | plugin                |
    +-----------+------------------+-----------------------+
    | localhost | mysql.infoschema | caching_sha2_password |
    | localhost | mysql.session    | caching_sha2_password |
    | localhost | mysql.sys        | caching_sha2_password |
    | localhost | root             | mysql_native_password |
    +-----------+------------------+-----------------------+
    4 rows in set (0.01 sec)

     

    plugin의 방식이 mysql_native_password으로 잘 바뀌었음을 알 수 있다.

     

    오류를 해결하기 위해 여러 글을 보는 중 (맥북 기준) cd /opt/homebrew/etc/my.cnf 위치의 my.cnf 파일에 default-authentication-plugin=mysql_native_password 설정을 추가하라는 얘기도 있었다.

    하지만 굳이 디폴트 설정을 안 해도 MySQL이 동작하는데 문제없었기 때문에 따로 해주지는 않았다.

     

    혹시나 나처럼 여러 글을 보면서 헷갈릴 사람이 있을까 봐 사족을 붙인다.

     

    이제 MySQL 접속이 잘된다. (이제 코드 짤 수 있게 되어 행복하다... 으헝)

    반응형

    댓글

Designed by Tistory.