๊ธ€ ์ž‘์„ฑ์ž: ๋˜ฅํด๋ฒ .
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

MySQL 8.0์—์„œ NodeJS์˜ mysql ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Connect ํ•˜๋Š” ์ค‘ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค.

 

  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 ํ”Œ๋Ÿฌ๊ทธ์ธ์œผ๋กœ๋Š” ์ง€์›๋˜์ง€ ์•Š๋Š” ๋ฐฉ์‹์ด๊ธฐ ๋•Œ๋ฌธ์— ์ ‘์†์„ ํ•˜์ง€ ๋ชปํ•œ๋‹ค.

 

mysql_native_password์™€ caching_sha2_password์˜ ์ฐจ์ด๋Š” ๋ณด์•ˆ์„ฑ์— ์žˆ๋‹ค.

https://dev.mysql.com/doc/refman/8.0/en/caching-sha2-pluggable-authentication.html

 

MySQL :: MySQL 8.0 Reference Manual :: 6.4.1.2 Caching SHA-2 Pluggable Authentication

MySQL 8.0 Reference Manual  /  ...  /  Security  /  Security Components and Plugins  /  Authentication Plugins  /  Caching SHA-2 Pluggable Authentication 6.4.1.2 Caching SHA-2 Pluggable Authentication MySQL provides two authentication plugins th

dev.mysql.com

์š”์•ฝํ•˜์ž๋ฉด, mysql_native_password๋Š” ๋น„๋ฐ€๋ฒˆํ˜ธ ๋…ธ์ถœ์˜ ์œ„ํ—˜์ด ์žˆ์–ด caching_sha2_password๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋Š” ๊ฒƒ.

 

 

ํ•ด๊ฒฐ

๋ฐฉ๋ฒ• 1. mysql2 ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‚ฌ์šฉ

๊ฐ€์žฅ ๊ฐ„๋‹จํ•œ ๋ฐฉ๋ฒ•์ด๋‹ค. API๋“ค์ด ๊ธฐ์กด mysql ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์™€ ํ˜ธํ™˜๋˜์–ด์žˆ์–ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ํฌํ•จ์‹œํ‚ค๋Š” ๋ถ€๋ถ„๋งŒ ๋ฐ”๊พธ๋ฉด ๋œ๋‹ค.

 

mysql ์„ค์น˜

npm install mysql2

 

์‚ฌ์šฉ ๋ถ€๋ถ„ ๊ต์ฒด

import * as mysql from 'mysql2';

 

 

 

๋ฐฉ๋ฒ• 2. (๋น„์ถ”์ฒœ)

๋ณด์•ˆ์˜ ์œ„ํ—˜์„ฑ๋•Œ๋ฌธ์— ๋‹น์—ฐ์ง€์‚ฌ, ๋ฐฉ๋ฒ• 1๋กœ ํ•ด๊ฒฐํ•ด์•ผ ๋˜์ง€๋งŒ ํ”ผ์น˜ ๋ชปํ•  ์‚ฌ์ •์œผ๋กœ ๋ฐฉ๋ฒ• 1์„ ์ ์šฉํ•  ์ˆ˜ ์—†๋Š” ์ƒํ™ฉ์ด๋ผ๋ฉด

๋‹ค์Œ๊ณผ ๊ฐ™์ด ํŒจ์Šค์›Œ๋“œ ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ๋ฐ”๊พธ๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ ํ•ด๊ฒฐํ•œ๋‹ค.

 

ALTER USER '๊ณ„์ • ์ด๋ฆ„' IDENTIFIED WITH mysql_native_password BY '๊ณ„์ • ๋น„๋ฐ€๋ฒˆํ˜ธ';

 

 

๋ฐ˜์‘ํ˜•