简体   繁体   English

Wndows 10 / Node.js无法连接到mySQL服务器

[英]Can't connect to mySQL server, Wndows 10/Node.js

I have a discord bot that has been connecting to my database as follows: 我有一个不和谐的bot,它已按如下所示连接到我的数据库:

var con_database = mysql.createConnection({
host: "localhost",
user: "root",
password: "mypass",
database: "cordtrax"
});

It has been connecting flawlessly for days now, but suddenly when I start my bot with nodemon, I get the following error: 它已经完美地连接了好几天了,但是当我用nodemon启动我的机器人时,突然出现以下错误:

{ Error: connect ECONNREFUSED 127.0.0.1:3306
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1191:14)
--------------------
at Protocol._enqueue (C:\Users\markm\Documents\Projects\bot\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (C:\Users\markm\Documents\Projects\bot\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at Connection.connect (C:\Users\markm\Documents\Projects\bot\node_modules\mysql\lib\Connection.js:118:18)
at Object.<anonymous> (C:\Users\markm\Documents\Projects\bot\bot.js:52:14)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Function.Module.runMain (module.js:694:10)
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 3306,
fatal: true }

The same error occurs when starting the bot using regular node. 使用常规节点启动漫游器时,会发生相同的错误。 When I try to connect through my mySQL 8.0 command line client, the client closes instantly after inputting my password. 当我尝试通过mySQL 8.0命令行客户端进行连接时,客户端在输入密码后立即关闭。 When I try and connect through the command line using mysql -h localhost I get the following error: 当我尝试使用mysql -h localhost通过命令行连接时,出现以下错误:

ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)

Every guide I have seen so far recommends going to services and starting the mySQL service manually. 到目前为止,我看过的每本指南都建议您去服务并手动启动mySQL服务。 When I try this, I get the pop up message saying the service has started and stopped. 尝试此操作时,我会收到一条弹出消息,提示服务已启动和停止。

I think MySQL Server is not installed properly. 我认为MySQL Server未正确安装。 Install it fresh again. 再次重新安装。 Then confirm that service is started. 然后确认服务已启动。 If Service is not started, you cannot connect. 如果未启动服务,则无法连接。

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

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