繁体   English   中英

为什么当xampp运行mysql时我的Node.js代码可以工作,而当mysql notifier运行mysql服务器时却不能运行?

[英]Why is my Node.js code working when xampp is running mysql, but not when mysql notifier has mysql server running?

我是使用node.js和mysql的新手,我有一个简单的脚本,该脚本使用node将我登录到mysql服务器。

var mysql = require('mysql');
var connection = mysql.createConnection({
  host     : 'localhost',
  user     : 'root',
  password : ''
});
connection.connect(function(err) 
{
  if (!err)
    console.log('Connected');
  else
    console.log('Error connection');
    console.log(err);
});

当我的xampp mysql服务器运行时,它返回已连接;但是,当xampp关闭并且mysql服务器通知程序正在运行时,它返回此错误。

代码:'ER_NOT_SUPPORTED_AUTH_MODE',错误:1251,sqlMessage:'客户端不支持服务器请求的身份验证协议;请考虑升级MySQL客户端',sqlState:'08004',致命:true} ”我使用了Windows上的安装程序mysql站点。 我正在运行Windows 10,它将直接安装到计算机的C驱动器中。

您可以通过执行以下命令来尝试:

use mysql;
update user set authentication_string=password(''), plugin='mysql_native_password' where user='root';

我不知道什么是MySQL Notifier,所以我在Google上进行了搜索。 根据我在此处找到的文档(www.mysql.com) ,MySQL Notifier仅通知系统上的更改以及与MySQL Server的连接。

这意味着该实用工具不是 MySQL服务器,您不能像以前那样使用它。 您需要一个正在运行的MySQL服务器(由xamp启动)。

在没有xamp的情况下运行MySQL服务器的方法有很多:

无论如何,您的服务器版本与您的客户端版本不匹配,这是您的mysql Node.js库。 这两个版本可以互相配合使用,但是身份验证方法似乎已更改。

您使用哪个版本? 您是否尝试更新它? npm update mysql

最好的解决方案可能在这里: mysqljs GitHub存储库中有关此主题的一个封闭问题,Andrey Sidorov建议

允许使用不安全的身份验证: https : //github.com/mysqljs/mysql#connection-options insecureAuth选项。

来源: https : //github.com/mysqljs/mysql/issues/1574

选项说明:

  • insecureAuth:允许连接到要求使用旧的(不安全的)身份验证方法的MySQL实例。 (默认值:false)

https://github.com/mysqljs/mysql#connection-options

您可以尝试将此选项设置为true

var connection = mysql.createConnection({
  host     : 'localhost',
  user     : 'root',
  password : '',
  insecureAuth: true
});

只是一点点,“ xamp”代表“ LinuX Apache MySQL PHP”(因此您使用的是“ wamp”->“ Windows Apache MySQL PHP”)。

如果您运行的是MySQL 8.0,则可能会遇到此处所述的相同问题(并且可以使用相同的解决方案来解决)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM