提问者:小点点

通过Node. js访问MySQL-DB(在plesk服务器上)


我刚刚购买了自己的域名,包括plesk服务器上的虚拟主机。幸运的是,他们还提供了一个MySQL数据库。当我插入凭据时,通过MySQL工作台(本地)访问DB工作得很好(由于某种原因,唯一的工作连接方法是“标准TCP/IPSSH”(它甚至不需要私钥的位置)),但我找不到使用node. js进行此工作的方法。(我使用的是版本8.11.1)。

我决定使用node. js,因为我想使用d3进行一些交互式数据可视化,并且由于我有近40000个数据点,我想将尽可能多的进程外包给服务器。

当然,我想在本地和服务器上尝试所有内容。

根据我在工作台上使用的连接方法,我怀疑使用了一些ssh-module(仅仅使用mysql模块也不行)。现在我尝试了这些:

> mysql-ssh(https://www.npmjs.com/package/mysql-ssh)

只需将我的凭据(包括私钥)放入示例代码即可返回此错误:

events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: All configured authentication methods failed
    at tryNextAuth (C:\Users\matth\git\soundstats_elak_titles\node_modules\ssh2\lib\client.js:380:17)
    at SSH2Stream.onUSERAUTH_FAILURE (C:\Users\matth\git\soundstats_elak_titles\node_modules\ssh2\lib\client.js:591:5)
    at emitTwo (events.js:126:13)
    at SSH2Stream.emit (events.js:214:7)
    at parsePacket (C:\Users\matth\git\soundstats_elak_titles\node_modules\ssh2-streams\lib\ssh.js:3929:10)
    at SSH2Stream._transform (C:\Users\matth\git\soundstats_elak_titles\node_modules\ssh2-streams\lib\ssh.js:669:13)
    at SSH2Stream.Transform._read (_stream_transform.js:186:10)
    at SSH2Stream._read (C:\Users\matth\git\soundstats_elak_titles\node_modules\ssh2-streams\lib\ssh.js:251:15)
    at SSH2Stream.Transform._write (_stream_transform.js:174:12)
    at doWrite (_stream_writable.js:397:12)

Process finished with exit code 1

根据我的解释,mysqlssh. connect中的第一个块相当于mysql工作台连接配置中的字段SSH主机名和SSH用户名,而第二个块相当于MySQL主机名和用户名

在此示例中插入凭据我首先收到了这些消息

(node:6548) UnhandledPromiseRejectionWarning: null
(node:6548) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:6548) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

等待几分钟后,程序以以下消息结束:

events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: read ECONNRESET
    at _errnoException (util.js:1022:11)
    at TCP.onread (net.js:628:25)

Process finished with exit code 1

这里凭证块的顺序似乎与mysql-ssh相比发生了变化


共1个答案

匿名用户

看起来mysql-ssh在幕后使用node-mysql2,它目前不支持MySQL 8.0使用的新默认身份验证插件。

更多详细信息可在此处获得。