MySQL 8.0-클라이언트는 서버가 요청한 인증 프로토콜을 지원하지 않습니다. MySQL 클라이언트 업그레이드 고려
나는 node.js와 MySQL 초보자이며 방금 기본 코드를 설정하고 시도하기 시작했습니다. 그러나 어떤 이유로 든 서버에 간단한 연결조차 할 수 없습니다. 기본 설정으로 Node.JS와 함께 최신 MySQL Community 8.0 데이터베이스를 설치합니다.
이것은 내 node.js 코드입니다
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "password",
insecureAuth : true
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});
아래는 명령 프롬프트에서 발견 된 오류입니다.
C:\Users\mysql-test>node app.js
C:\Users\mysql-test\node_modules\mysql\lib\protocol\Parse
r.js:80
throw err; // Rethrow non-MySQL errors
^
Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
at Handshake.Sequence._packetToError (C:\Users\mysql-
test\node_modules\mysql\lib\protocol\sequences\Sequence.js:52:14)
at Handshake.ErrorPacket (C:\Users\mysql-test\node_mo
dules\mysql\lib\protocol\sequences\Handshake.js:130:18)
at Protocol._parsePacket (C:\Users\mysql-test\node_mo
dules\mysql\lib\protocol\Protocol.js:279:23)
at Parser.write (C:\Users\mysql-test\node_modules\mys
ql\lib\protocol\Parser.js:76:12)
at Protocol.write (C:\Users\mysql-test\node_modules\m
ysql\lib\protocol\Protocol.js:39:16)
at Socket.<anonymous> (C:\Users\mysql-test\node_modul
es\mysql\lib\Connection.js:103:28)
at Socket.emit (events.js:159:13)
at addChunk (_stream_readable.js:265:12)
at readableAddChunk (_stream_readable.js:252:11)
at Socket.Readable.push (_stream_readable.js:209:10)
--------------------
at Protocol._enqueue (C:\Users\mysql-test\node_module
s\mysql\lib\protocol\Protocol.js:145:48)
at Protocol.handshake (C:\Users\mysql-test\node_modul
es\mysql\lib\protocol\Protocol.js:52:23)
at Connection.connect (C:\Users\mysql-test\node_modul
es\mysql\lib\Connection.js:130:18)
at Object.<anonymous> (C:\Users\mysql-test\server.js:
11:5)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Function.Module.runMain (module.js:701:10)
https://dev.mysql.com/doc/refman/5.5/en/old-client.html https://github.com/mysqljs/mysql/issues/1507 과 같은 것들을 읽었습니다.
그러나 여전히 내 문제를 해결하는 방법을 모르겠습니다. 도움을 주시면 감사하겠습니다 .D
MYSQL Workbench에서 다음 쿼리 실행
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'
어디 root
사용자로 localhost
당신의 URL로와 password
비밀번호 등
연결 한 후 노드를 사용하여 연결해보십시오
이전 mysql_native_password
작품 사용하기 :
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YourRootPassword';
-- or
CREATE USER 'foo'@'%' IDENTIFIED WITH mysql_native_password BY 'bar';
-- then
FLUSH PRIVILEGES;
이는되는 caching_sha2_password
MySQL은 8.0에서 소개되어 있지만 Node.js를 버전은 아직 구현되지 않았습니다. 당신이 볼 수있는 이 풀 요청 하고 이 문제에 대한 자세한 내용입니다. 아마도 수정이 곧 올 것입니다!
먼저 무슨 일이 일어나고 있는지 분명히하자.
MySQL 8은 플러그 가능한 인증 방법을 지원합니다. 기본적으로 caching_sha2_password
우리의 좋은 예전 mysql_native_password
( source ) 대신 이름 이 지정된 것이 사용됩니다 . 여러 핸드 셰이크와 함께 암호화 알고리즘을 사용하는 것이 24 년 동안 존재했던 일반 암호 전달보다 더 안전합니다 !
이제 문제는 mysqljs
Node ( npm i mysql
노드 코드 와 함께 설치하여 사용 하는 패키지 )에서 아직 MySQL 8의이 새로운 기본 인증 방법을 지원하지 않습니다. 이 문제는 https://github.com/mysqljs/mysql/issues/1507에 있으며 2019 년 7 월 현재 3 년이 지난 후에도 계속 열려 있습니다 (2019 년 6 월 업데이트 : mysqljs에 새로운 PR 이 수정되었습니다) 이!)
당신의 옵션
옵션 1) 좋은 "native_password"를 사용하여 인증하기 위해 "MySQL"을 다운 그레이드
그것이 모두가 여기에서 제안하는 것입니다 (예 : 위의 답변 ). 당신 은 인증에 대한 오래된 방법을 사용하여 괜찮다고 mysql
말하는 쿼리를 시작 하고 실행합니다 .root
native_password
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password ...
좋은 점은 인생이 단순해질 것이며 여전히 아무 문제 없이 Sequel Pro와 같은 오래된 도구를 사용할 수 있다는 것 입니다. 그러나 문제는 당신이 사용할 수있는보다 안전한 (그리고 시원하고 읽을 수있는) 것들을 이용하지 않는다는 것입니다.
옵션 2) "Node"패키지를 MySQL Connecter X DevAPI로 교체
MySQL X DevAPI for Node 는 http://dev.mysql.com 공식 사용자가 제공하는 Node의 Mysqljs 패키지를 대체합니다 .
caching_sha2_password
인증을 지원하는 매력처럼 작동 합니다. ( X 프로토콜 통신에 포트 33060
를 사용해야 합니다.)
나쁜 점은 mysql
모든 사람들이 익숙하고 의존하는 오래된 패키지를 남겼다는 것입니다 .
좋은 점은 앱이 더 안전 해졌으며 오랜 친구들이 제공하지 않은 새로운 것들을 활용할 수 있다는 것입니다. X DevAPI 의 튜토리얼을 확인하면 유용한 새로운 섹시한 기능이 많이 있음을 알 수 있습니다. 기술 업그레이드와 함께 제공되는 학습 곡선의 가격 만 지불하면됩니다. :)
추신. 불행하게도,이 XDevAPI 패키지는 타입 정의 (TypeScript가 이해할 수없는)를 아직 가지고 있지 않으므로 typescript 를 사용하면 문제가 발생합니다. 나는 .d.ts 사용하지 생성하기 위해 노력 dts-gen
하고 dtsmake
있지만 성공. 따라서 명심하십시오.
건배!
수락 된 답변은 정확하지만 새 사용자를 만든 다음 해당 사용자를 사용하여 데이터베이스에 액세스하는 것이 좋습니다.
create user nodeuser@localhost identified by 'nodeuser@1234';
grant all privileges on node.* to nodeuser@localhost;
ALTER USER 'nodeuser'@localhost IDENTIFIED WITH mysql_native_password BY 'nodeuser@1234';
MySQL 8의 전체 단계
MySQL에 연결
$ mysql -u root -p
Enter password: (enter your root password)
비밀번호를 재설정
( your_new_password
사용하려는 비밀번호로 교체 )
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_new_password';
mysql> FLUSH PRIVILEGES;
mysql> quit
그런 다음 노드를 사용하여 연결을 시도하십시오.
MySQL의 최신 도커 컨테이너
ALTER USER root IDENTIFIED WITH mysql_native_password BY 'password';
이 오류가 발생했지만 여전히 MySQL 버전 8을 사용하려는 경우 Docker를 사용하여 데이터베이스를 작성할 때 MySQL 서버에 레거시 인증 플러그인을 사용하도록 지시하여이를 수행 할 수 있습니다.
따라서 작성 파일은 다음과 같습니다.
# Use root/example as user/password credentials
version: '3.1'
services:
db:
image: mysql:8.0.15
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: 'pass'
MYSQL_DATABASE: 'db'
MYSQL_USER: 'user'
MYSQL_PASSWORD: 'pass'
ports:
- 3318:3306
# Change this to your local path
volumes:
- ~/Database/ORM_Test:/var/lib/mysql
원본 문서는 여기에서 찾을 수 있습니다 : https://dev.mysql.com/doc/dev/connector-nodejs/8.0/
'use strict';
const mysqlx = require('@mysql/xdevapi');
const options = {
host: 'localhost',
port: 33060,
password: '******',
user: 'root',
schema: 'yourconference'
};
mysqlx.getSession(options)
.then(session => {
console.log(session.inspect());
session.close();
}).catch(err => {
console.error(err.stack);
process.exit(1);
});
ALTER USER ... 명령 행이 작동하지 않고 Windows 10을 사용중인 경우 다음 단계를 수행하십시오.
1) Windows 검색 창에 MySQL을 입력하십시오.
2) MySQL Windows Installer 열기-커뮤니티
3) "MySQL 서버"를 찾아 재구성을 클릭하십시오.
4) Click on "Next" until you reach the "Authentification Method" phase
5) On the "Authentification Method" phase check the second option "Use Legacy Authentication Method"
6) Then follow the steps given by the Windows installer until the end
7) When it's done, go into "Services" from the Windows search bar, click on "start" MySql81".
Now, try again, the connection between MySQL and Node.js should work!
I have MYSQL on server and nodejs application on another server
Execute the following query in MYSQL Workbench
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password'
For existing mysql 8.0 installs on Windows 10 mysql,
(1) launch installer,
(2) click "Reconfigure" under QuickAction (to the left of MySQL Server), then
(3) click next to advance through the next 2 screens until arriving
(4) at "Authentication Method", select "Use Legacy Authentication Method (Retain MySQL 5.x compatibility"
(5) Keep clicking until install is complete
In MySQL 8.0,
caching_sha2_password
is the default authentication plugin rather thanmysql_native_password. ...
Most of the answers in this question result in a downgrade to the authentication mechanism from caching_sha2_password
to mysql_native_password
. From a security perspective, this is quite disappointing.
This document extensively discusses caching_sha2_password
and of course why it should NOT be a first choice to downgrade the authentication method.
With that, I believe Aidin's answer should be the accepted answer. Instead of downgrading the authentication method, use a connector which matches the server's version instead.
Just Run MySQL Server Installer and Reconfigure the My SQL Server...This worked for me.
I have the same problem with MySQL and I solve by using XAMPP to connect with MySQL and stop the services in windows for MySQL (control panel - Administrative Tools - Services), and in the folder db.js (that responsible for the database ) I make the password empty (here you can see:)
const mysql = require('mysql');
const connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: ''
});
Check privileges and username/password for your MySQL user.
For catching errors it is always useful to use overrided _delegateError
method. In your case this has to look like:
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "password",
insecureAuth : true
});
var _delegateError = con._protocol._delegateError;
con._protocol._delegateError = function(err, sequence) {
if (err.fatal)
console.trace('MySQL fatal error: ' + err.message);
return _delegateError.call(this, err, sequence);
};
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});
This construction will help you to trace fatal errors.
'IT' 카테고리의 다른 글
존재하지 않고 새 줄을 추가하는 경우 .txt 파일을 만듭니다. (0) | 2020.06.15 |
---|---|
데몬 프로세스로 PHP 스크립트를 실행 (0) | 2020.06.14 |
Android Studio에서 벡터 자산의 채우기 색상 변경 (0) | 2020.06.14 |
모두 거부, htaccess를 통해 하나의 IP 만 허용 (0) | 2020.06.14 |
PostgreSQL 클라이언트 라이브러리를 찾을 수 없습니다 (libpq) (0) | 2020.06.14 |