Viewed   6.7k times

I'm new to nodeJs and trying to develop my first application. I installed mysql package through npm, It got installed and I can see a successful entry of it in package.json. However, when I'm trying to connect to mysql server, it gives me this error connect ECONNREFUSED I searched for this issue on StackOverflow and the other users who had the very same issue got it running by adding an entry socketPath: '/var/run/mysqld/mysqld.sock' to the configuration object. But when I added this to my configuration object, I got a new error connect ENOENT /var/run/mysqld/mysqld.sock.

Here's the code by which I'm trying to connect to the server

var express = require('express');
var router = express.Router();
var mysql = require('mysql');
var connection = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: '',
    database: 'blog',
    socketPath: '/var/run/mysqld/mysqld.sock'

module.exports = router;

I'm using a Windows machine and had mysql installed before via XAMPP package. Can this be the reason behind the connection failure?



Have you started your XAMPP Server ?.

connect ECONNREFUSED -- this error came, when you not started your XAMPP server.

Please remove socketPath & try once.

I have faced same kind of issue, when I not started the XAMPP server.

Sunday, October 23, 2022

I reached out to the node-mysql folks on their Github page and got some firm answers.

  1. MySQL does indeed prune idle connections. There's a MySQL variable "wait_timeout" that sets the number of second before timeout and the default is 8 hours. We can set the default to be much larger than that. Use show variables like 'wait_timeout'; to view your timeout setting and set wait_timeout=28800; to change it.

  2. According to this issue, node-mysql doesn't prune pool connections after these sorts of disconnections. The module developers recommended using a heartbeat to keep the connection alive such as calling SELECT 1; on an interval. They also recommended using the node-pool module and its idleTimeoutMillis option to automatically prune idle connections.

Friday, August 26, 2022

The "fail to connect to camera service" means that your (or some other) camera app has failed to release camera properly. This was happening to me occasionally as I was developing my app, too. The first thing I'd try is to open the camera from the default camera app that comes with the phone (just tapping the "camera" button). If that would fail to open, then the only option was to restart the phone.

This is speculation, but your code might have a bug that surfaces only occasionally and it just didn't appear until now through pure luck. If it persist, check out the questions related to "how to release camera properly in android". They had helped me to deal with this.

Thursday, November 24, 2022

I'm the author of node-mysql-native driver, from my point of view the differences are

  1. no prepared statements support (yet) in node-mysql
  2. according to my benchmarks node-mysql is 10-20% slower than node-mysql-native
  3. node-mysql has much wider adoption, more tests and users. If you need stability, better use it
  4. node-mysql-libmysqlclient is 2 to 3 times faster on fast queries. However, if you have a lot of slow queries and use connection pools it could be even slower than native JS driver because libmysqlclient async calls are based on nodejs thread pool and not on event loop.


As of 11/07/2013

  • (2). no longer valid (mysql-native is a bit slower than node-mysql)
  • have this alternative to node-mysql, on some benchmarks it's 2-3 times faster, has same API + support for prepared statements, SSL and compression. Also implements simple subset of server side protocol - see for example MySQL -> Postgres proxy.
  • node-mariasql is also a very good option (if it's ok to use binary addon) - fast, stable, async, prepared statements support, compression and SSL.
Tuesday, October 25, 2022

It sounds like you haven't started and configured the backend for Nginx. Start php-fpm and add the following to nginx.conf, in the http context:

server {
    server_name localhost;

    error_log /var/log/nginx/localhost.error_log info;

    root /var/www/localhost/htdocs;

    location ~ .php$ {
        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;

        fastcgi_intercept_errors        on;
        error_page 404 /error/404.php;
Friday, November 18, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :