-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Module does not work in Node.js 0.6 (was: ECONNREFUSED) #718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Interesting how you're loading the mysql module - why not:
|
|
@jdrydn I load it in that way because npm install mysql put it in subdirectory of the project. @sidorares The server is local and I can connect to it by CLI (
Thank you guys. |
Yeh, NPM installs modules to a (Therefore, |
@jdrydn do you think this is the problem? What do you mean exactly with up the hierarchy? |
No, I think the problem lies in your database config, especially if you can connect over the CLI, could you comment with the object you have at |
I.e. Mine often looks like: var config = {
database: {
host: "localhost",
user: "myawesomeuser",
password: "mysecurepassword",
database: "thedatabase"
}
};
var mysql = require("mysql");
var connection = mysql.createConnection(config.database); |
Thank you. This is the definition of config.db. exports.db = {
host: '127.0.0.1',
user: 'user',
password: 'passwd',
database: 'zadmin_shopriparando'
}; |
What settings do you think are wrong with my DB? |
What I would do, for debugging irritating connection issues like this, is put the contents of the example (https://github.com/felixge/node-mysql#introduction) into a file Do you still get a connection issue? Edit: If no, then perhaps it's a problem with your user not being able to access your database? Check the privileges of of your database, make sure the user can do stuff on the database. |
The problem persists. I tried with var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'testdb',
user: 'me',
password: 'beryqeqes',
database: 'zadmin_testdb'
});
connection.connect(); but I get the same error. I do not know if it matters, but we use ZPanel to manage databases and users. |
Take off the database parameter, can you connect to the MySQL server? |
No. Same error :( |
Possibly stupid question but: you do actually have a mysql server running, right? @jdrydn sup ;) |
@PhUU sure. I can also connect to the database through CLI, with the same credentials I use in the script. |
This simply means that you cannot connect to MySQL because it has networking disabled. You can connect to it using the UNIX socket. Get the path using |
@PhUU Sup dawg ;) |
@dougwilson thank you. I will try as soon as I can. |
|
I got the same error as below while running
I guessed it as missing of MySQL. What may be the possible good solution for this Error. |
Can confirm same issue as OP. Have one lamp stack, php connects without problems. node with mysql (from same host as db and default port) gives: connecting via socketPath works. |
@jacog this is not a bug. Your PHP is connecting over a UNIX socket, not over TCP. This module simply makes you explicitly chose instead of defaulting to a hard-coded UNIX socket path like PHP does. If you want to connect over TCP with this module, you'll need to enable networking in your MySQL server, otherwise continue to use the |
@dougwilson thanx for the info, I didn't know php does that by itself. It is a bit weird that even though in php you specify hostname / port and not socket path. Perhaps it does it because it is on the same box. I looked over the mysql cnf, didnt see anything disabling networking. Will have another look. Thanks. |
@jacog the setting is called |
@jacog The setting is probably in the |
@dougwilson Interesting thing is, I can connect to my server from my workstation (which is a different machine altogether) with mysql workbench - using ip / port. Well connecting via socket is fine. For anyone strugling with this, you can find your socketPath in |
@jacog it's possible your MySQL is bound and listening only on your external IP and not on your localhost as well. Another possibility is that your localhost is resolving to something weird so changing it to 127.0.0.1 may work. |
To everyone here, I'm going to close this issue since it has gotten very long as is not even a bug with this module unless there is a patch that fixes the issue. There are many ways you can check this. One way is to use
|
I am getting the same error; the MySQL server I am trying to connect to is on a different host, and I can connect to it via the CLI client as well as via PHP, by specifying its IP (it also works by specifying its DNS name). I can also telnet to it. var mysql = require('mysql');
var connection = mysql.createConnection({
host: 'db.domain.tld',
user: 'myuser',
password: 'secret',
database: 'something'
});
connection.connect(function(err) {
console.log(err);
}); Can you please tell me how to test further, to find the exact cause of the issue? |
@loicAG |
Whilst I haven't had this problem in a while, my comment up there turned out to be false (socket path merely led to a different error). Attempting to connect to the database from the command line worked perfectly. In the end I gave up with node-mysql and switched to sequelize which connected first time... That seems to me like it's a bug with node-mysql itself. |
@cazcazn |
Hmm so the only thing different in the way sequelize connects is it adds a port and a timezone. Like I say, I haven't looked at this in a while so can't play with anything, was just adding what worked for me. |
This might be a dumb question, but what version of NodeJS are you using? I once accidentally reinstalled 0.6 instead of 0.10, and I had this issue. |
FIX: make sure you are using the latest version of nodejs. This library doesn't work with node 0.6 Just had this exact issue. Appears that for some reason this library is incompatible with node 0.6. Tried everything suggested on this thread along with every other thread I could Google, but evanmoss was the only one that worked. You might want to think about including a version check in the library on load and refuse to activate the module if the version if incompatible. |
@JalfResi there is a version check: https://github.com/felixge/node-mysql/blob/master/package.json#L28 The |
My issue - at least - was that I was using a PaaS, so if it spit some error On Friday, August 29, 2014, Douglas Christopher Wilson <
|
Sure :) It's just Node.js does not give us a way to check the version in runtime--all there is is a string like |
I installed it via npm and no error was raised during install. If there was an error message, and I missed it, it still installed the library successfully. This is a flaw. If the library is incompatible then it shouldn't install at all, unless I force it. It did nothing of the sort and installed it successfully with no error message (that I could see). I'm new to nodejs and I must say that things issues like this are fustrating. On top of that, now it appears that there is a problem with the MySQL insert statement; I keep getting . So it appears that not only does this library NOT check which version of node it is installed against, it now appears that it doesn't check which version of MySQL it is connecting to, as I now get the error message "1 query failed: Error: ER_PARSE_ERROR: You have an error in your SQL syntax;" I got it to dump out the SQL it's trying to run and ran it on the mysql command line client and it runs without error. |
Which version of MySQL does this library support? Which version of the MySQL client does the parser support? |
Seriously open a new issue. This issue is about ECONNREFUSED which you are not experiencing. This library adds the appropriate checks for now 0.8+. If it installs, it is a bug in npm which does the install incorrectly, not this library, as this library has no control over the install except telling npm the requirements, which it does.
This library supports MySQL 4 and up.
As for your SQL error, you are giving invalid SQL. This library does nothing with the SQL except forwards it to the server, so it supports whatever SQL your MySQL server does. You can refer to your MySQL server manual to know what your server supports. |
Hi! For all those who stumble upon this issue, if you just always seem to be getting the If you believe you are having an issue with the module, please feel free to open a new issue by going to https://github.com/felixge/node-mysql/issues/new |
Hello.
I'm trying to connect to MySQL server in this way.
but I get this error:
I tried all the solution on the web but nothing worked.
The text was updated successfully, but these errors were encountered: