MySQL lost connection with system error: 10060 - mysql

I am studying react and node js, to build a full stack login authentication page.
Which I found tutorial from this github : "https://github.com/bezkoder/node-js-jwt-auth".
I found this tutorial extremely confusing due to mysql connection errors, the only edit I made is changing the running port from 8080 to 3306, which is a fast fix for having another port running on 8080.
When I run "node server.js" this error pops up few seconds
also, in order to view mysql databases, I am running MySQL Workbench localhost:3306, but the server is stopped, refresh wouldn't work, nor restarting the mysql through services.
The Message shows: Lost connection to MySQL server at 'waiting for initial communication packet'. system error 10060.
Please help, I have no idea what I am doing.

you didn't learn how node.js or react work, so start with much simpler tutorials
port 8080 is the port when you type it in the browser localhost:8080 a webpage appears.
So don't change it, as long as you don't have another page running.
You start by editng
node-js-jwt-auth/app/config/db.config.js
There you find
module.exports = {
HOST: "localhost",
USER: "root",
PASSWORD: "123456",
DB: "testdb",
dialect: "mysql",
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
}
};
Here you enter the same data as you enter in workbench.
Of course the mysql server has to be installed and running.

Related

Sequelize Access Denied

I'm running an AWS Lightsail linux instance with Node. I've manually installed MySQL and after some time, have connected successfully from my machine using MySql Workbench. I'm now using Node and Sequelize (local machine) to develop against this remote database. In trying to connect, I'm getting an Access Denied error in Node. Same creds as Workbench but not working.
Wondering if something looks obviously wrong here. I've rechecked the credentials as well. And the AWS instance is at a static IP, so, I'm using that as my connection URL host.
const sequelize = new Sequelize(
process.env.DB_DATABASE,
process.env.DB_USERNAME,
process.env.DB_PASSWORD,
{
host: process.env.DB_HOST, // example 25.13.15.200
dialect: "mysql",
port: 3306,
pool: {
max: 5, // max pool connections
min: 0, // mix pool connections
acquire: 30000, // max time (in ms) that pool will try to get connection before throwing an error
idle: 10000, // max time (in ms) that a connection can be idle before being released
},
operatorAliases: false,
}
);
The error I'm getting in my node server is
Checking database connection...
Unable to connect to the database
Access denied for user 'xxxxxx'#'%' to database 'xxxxxxx' // xxxxxx is to cover actual name
Starting Node / Express server on port 5000
It turned out to be permissions needing to be opened for the account. Was odd however because the connection was successful in workbench but via node/sequelize it didn’t work.
This post helped a lot.
Cannot connect to Database server (mysql workbench)

"ECONNREFUSED" while connecting to docker mysql container in NodeJS application

I am trying to do the following in the NodeJS application which is running on MAC OSX: (Docker REST API's are used to interact with docker.
API Reference: https://docs.docker.com/engine/reference/api/docker_remote_api_v1.23/)
Create mysql docker container, mapping its port 3306 to one of the host port. This is the docker container configuration POST body:
{
'Env': ['MYSQL_ROOT_PASSWORD=root'],
'Image': 'test-mysql',
'ExposedPorts': {
'3306/tcp': {}
},
'HostConfig': {
'PortBindings': { '3306/tcp': [{}]}
}
Start this newly created mysql docker container.
Fetch the docker container port 3306 host mapping from the host config, by inspecting the container. (Assume the mapping maps mysql container port 3306 to port 32789 of the host)
Create a mysql connection using the following mysql npm module https://www.npmjs.com/package/mysql.
Connection config is:
{
host: dockerHostIp, // 192.168.99.100 -- docker host IP
port: portMappingFromStep3, //32789
user: mySQLUser,
password: mySQLUserPassword,
database: 'mysql'
}
Running all this step sequentially throws an error while setting up mysql connection. It produces following output:
{
[Error: connect ECONNREFUSED 192.168.99.100:32789]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '192.168.99.100',
port: 32800,
fatal: true
}
But, if I provide a timeout of around 7-8 seconds before establishing up the mysql connection, connection establishes successfully.
Not sure, what is happening over here. I am not able to understand, why without timeout mysql connection is failing. I think it is something related to port mapping. Port mapping is taking some time to setup and providing timeout of roughly 7seconds, is covering up that mapping time.
I am trying to set up an end to end test environment where multiple mysql containers will be running in parallel. Waiting time of 7-8 seconds for the connection setup is a big overhead.
Any help to unravel this mystery will be very helpful.
Thanks

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'

errorError: getaddrinfo ENOTFOUND - mysql

I'm running a server on c9.io using Node.js and trying to connect to Mysql
I guess I get this error:
Error: getaddrinfo ENOTFOUND
because the connection to the db is wrong.
I'm using this:
var connection = mysql.createConnection({
host: "REMOTE_ADDR",
user: "MYUSERNAME", // this is replaced by my username
database: "c9",
port: 3306
});
Any idea what's wrong?
Thanks!
After one hour, and I don't know why, I found the issue.
In my case I replaced
host: 'localhost'
by
host: '127.0.0.1'
I know it's been a while since this was asked but I spent the better part of today trying to fix this. What to check for:
Within your nodejs source:
Try it without the 'port' option unless on your db VM, MySQL is
listening on a port besides 3306. I had this option specified but had
connection problems until I removed it. And 3306 is already the
default value for the option anyway.
Try it with the actual host IP in the host 'option'. I was using an actual domain name and, more often than not, node-mysql would throw
the same exact "errorError: getaddrinfo ENOTFOUND" When I used the IP
address, no more errors. Also, I did not get this error while on
Ubuntu instances in AWS. As soon as I switched over to Ubuntu VMs in
Azure, I got the problem.
Set the "debug" connection option to true which will give you a verbose trace of what's happening during the connection
On your db VM/Box/Instance:
Ensure that MySQL is listening on the right port
If you're seeing the error when trying to make concurrent connections using a pool, check that your max_connections and max_user_connections haven't been changed from the default settings in my.conf
Monitor "SHOW PROCESSLIST;" in MySQL to see if you see any issues there
This code works for me.
var mysql = require('mysql');
var con = mysql.createConnection({
host: '127.0.0.1',
port: '3306',
user: 'yourUsername',
password: '**********'
});
con.connect(function(err){
if(err) throw err;
console.log('connected!');
});
the host and port name find them in your mysql server.
in-place of '127.0.0.1' you can use 'localhost'
I was facing this issue. I did fix it simply you have to change your configuration of a connection string like if you are running on local machine try
host:'localhost' or host:'127.0.0.1'
...and set your user name and if you want this to publish your code on server then give the host according to server if in docker container give it name host:'db'.
I almost spend two hours to understand what is the problem with the mysql database. I am using Windows cmd.
I tried multiple ways e.g
npm install mysql2
Changing localhost to 127.0.0.1
Refreshing node
so in order to resolve this issue
[Error: getaddrinfo ENOTFOUND 127.0.0.1:3306]
I open XAMPP and start the MySQL database then manually check the credentials and works fine for me.
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'test',
password: 'test123',
});

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