Not able to connect MySQL with Sails js - mysql

I am using sails latest version(0.10.*), I am trying to connect mysql data base, but its throwing following error.
info: Starting app...
error: A hook (orm) failed to load!
error: Error (E_UNKNOWN) :: Encountered an unexpected error
: Query inactivity timeout
at Query. >(/home/pavan/pavanwork/development/plotstoday/node_modules/sails->mysql/node_modules/mysql/lib/protocol/Protocol.js:154:17)
at emitNone (events.js:67:13)
at Query.emit (events.js:166:7)
at Query._onTimeout >(/home/pavan/pavanwork/development/plotstoday/node_modules/sails->mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:116:8)
at Timer.listOnTimeout (timers.js:9
Configuration:
config/connection.js
mysqlServer: {
adapter: 'sails-mysql',
host: 'localhost',
user: 'root',
password: 'vtiger',
database: 'plotstoday'
},
config/model.js
module.exports.models = {
connection: 'mysqlServer',
migrate: 'alter'
};
config/env/development.js
models: {
//connection: 'localMongo'
connection: 'mysqlServer'
}
OS: Ubuntu 14.04 LTS
Installed both sails-mysql adapter and node-mysql adapter.
I even tried giving host:127.0.0.1.
Mysql is working fine from command-line, I tried the suggestion given
GRANT ALL PRIVILEGES ON sails.* TO 'homestead'#'%' WITH GRANT OPTION;
(Reference : Sails can not connect to mySql)
Please suggest

There is an issue with node(v4.2.0) and mysql. I was using node(v4.2.0), the above issue was coming. I upgraded to node v4.2.1, the above mysql timeout issue is resolved, and everything seems to be working

Related

Using MyXQL with Phoenix - Can't connect to database

I am using the MyXQL driver with Ecto in Phoenix, and am trying to connect to an already existing MySQL database running on a Debian 11 server.
I can access the server normally using mysql -p, and can access it through Express (which is what I was using before I started migrating to Phoenix / Elixir).
When I try to run:
{ :ok, pid } = MyXQL.start_link([ username: "{username}", password: "{password}" ])
I get an error that reads:
[error] MyXQL.Connection (#PID<0.449.0>) failed to connect: ** (DBConnection.ConnectionError) (/tmp/mysql.sock) no such file or directory - :enoent
I understand that this means it can't find a /tmp/mysql.sock socket, however I cannot figure out how to fix this error, or why it even is an error, considering ExpressJS can access the server (using the npm package mysql).

Cannot log in to mariadb from node.js app

I can log in with the same credentials from Windows Command Line and from MariaDB admin.
But trying to log in from node.js app fails...
const mariadb = require('mariadb');
const pool = mariadb.createPool({
host: 'localhost',
user:'nikol',
password: 'nbuser',
database: 'nodedb'
});
I get that error:
SqlError: Error during pool initialization: (conn=197, no: 1045, SQLState: 28000) Access denied for user 'nikol'#'localhost' (using password: YES)
I can also log in as root user from command line, but not from node js app.
Any suggestions?
Resolved. When installing MariaDB, I changed port number from 3306 to 3300 and that caused the problem. Now I have reinstalled MariaDB and everything works ok.

A hook (`orm`) failed to load! sailsjs

I have been trying since yesterday and somehow it's not working.
i dont know where am I going wrong with this.
here's the code in connections.js
module.exports.connections = {
mysql: {
adapter: 'sails-mysql',
host: 'localhost',
user: 'root', //optional
password: 'root', //optional
database: 'mysql' //optional
}
}
and here's the code in models.js
module.exports.models = {
connection:'mysql',
migrate:'alter'
}
could you guys tell me what's wrong here? and what's the reason for this error?
Here's the detailed error
error: A hook (`orm`) failed to load!
error: Error (E_UNKNOWN) :: Encountered an unexpected error
: Could not connect to MySQL:
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'#'localhost' (using password: YES)
at afterwards (/Users/faraz/code-playground/sailsapi/node_modules/sails-mysql/lib/connections/spawn.js:72:13)
at /Users/faraz/code-playground/sailsapi/node_modules/sails-mysql/lib/connections/spawn.js:40:7
at Handshake.onConnect [as _callback] (/Users/faraz/code-playground/sailsapi/node_modules/sails-mysql/node_modules/mysql/lib/Pool.js:54:9)
just wanted to show you the main page when I start mamp.
i think there's something wrong there
because it actually opens on http://localhost:8888/MAMP/?language=English but config shows port as 3306
could that be the problem??
here's a screenshot
I see that your configuration in sails is OK, so the reason why you cannot connect to the MySQL server is elsewhere. Here are some steps you may want to try:
Use phpMyAdmin to make sure you can connect to your server, but my guess is you will not be able to do that. If you do however, create a user for your DB there and grant all privileges for the DB to that user, and for host try to use "any host". Then adjust your connection according to that user.
In order to check your connection for the new user, the most convenient way is to use the MySQL Workbench tool from here: https://dev.mysql.com/downloads/workbench/
If all of that doesn't help, check this answer: Can't connect to MySQL server on 'localhost' (10061)

node/mysql/nginx - 502 bad gateway

I'm running a node app on ubuntu server 14.04 with nginx. I have a mysql database, which was initially running on a different server. Everything worked fine, but in an effort to tune performance I moved it onto the same server and I'm getting an error trying to connect through localhost. I'm using node-mysql with the following configuration:
host: 'localhost',
user: 'root',
password: 'xxx',
database: 'xxx'
I haven't really changed anything with mysql after the initial installation, simply created a dump file and ran it to create the database.
I get the following error whenever my app hits the database:
502 (Bad Gateway)
I've searched around but everything I find on this is PHP related.
Update:
Checked the pm2 logs (using pm2 to run node) and it's giving the following error:
ECONNREFUSED 127.0.0.1:3306
Is there something I need to do to open this up?
After being helped in the right direction via the comments and finding the real error, I was able to find the solution here. Needed to supply the mysql socket path in the node-mysql configuration.
host: 'localhost',
user: 'root',
password: 'xxx',
database: 'xxx',
socketPath: '/var/run/mysqld/mysqld.sock'

node-mysql error: connect ECONNREFUSED

I'm trying to setup a remote connection between my database server and a client node app using node-mysql.
When I try to connect to the remote db, I get this error:
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: connect ECONNREFUSED
at errnoException (net.js:646:11)
at Object.afterConnect [as oncomplete] (net.js:637:18)
Connecting to a local db works ok (with the socketPort parameter).
I can connect to this remote db with PHP from my computer localhost as well as another server I own so I don't think there's something wrong with mysql conf.
For info, nodejs is running with nginx and I've setup a proxy to make node work on port 80, maybe this is the issue?
How can I check that?
Thanks.
EDIT
Here's my code, just in case:
var express = require('express');
var mysql = require('mysql');
var app = express();
var connection = mysql.createConnection({
debug: false,
host: '12.34.56.67',
user: 'user',
password: 'pass'
});
Try using mysql socket:
var connection = mysql.createConnection({
user: 'user',
password: 'pass',
socketPath: 'mysql-socket-path', /*example: /Applications/MAMP/tmp/mysql/mysql.sock*/
database: 'dbname'
});
Should one still look for an answer:
Check your MySql server's configuration.
In my case running netstat -ln | grep mysql(as per Troubleshooting Problems Connecting to MySQL) revealed that my server is listening on the socket /tmp/mysql.sock so in createConnection's options I used socketPath: '/tmp/mysql.sock' instead of host: and port:
This error has to do with the MySQL client not being able to connect to the host:port given. As defined in errno.h, ECONNREFUSED is an error that is thrown when a connection is refused - this is possibly caused by:
a firewall such as iptables blocking the port
no such process running on the port
the process is running on a different host
the host or port were incorrect
In my case, my MySQL server was not correctly bound to 0.0.0.0 for external connections, instead being bound to 127.0.0.1, as it is by default; however you can change this.
The error does not originate from the node-mysql package, as doubly shown by the stacktrace, which only shows errors from net.js.
I added port:3306, that solved the issue .
var connection = mysql.createConnection
({
user: 'root',
password: 'root',
server: 'localhost',
port:3306,
database: 'abcd',
insecureAuth: true,
dialect: 'mysql',
multipleStatements: true,
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
}
});
connection.connect();
Ok so I checked with node-mysql dev and it seems that it's not a node-mysql bug, but it was hard to investigate more.
Anyway, I found this lib which works, so I'll go with it.
https://github.com/mariano/node-db-mysql
i had the same problem.
solved it, by set the right port in the createConnection function options.
get your port by using following command:
netstat -tlnp
search for program name mysqld or just named.
Use the command: yarn run start, and DO NOT use: cd /folderX && yarn run start