Error: connect ECONNREFUSED 192.168.7.2:3306

1,101 views
Skip to first unread message

Ichrak Mansour

unread,
Jun 26, 2018, 4:16:05 PM6/26/18
to BeagleBoard
I try to execute nodejs with mySQL with the code below :

var mysql = require('mysql');

var con = mysql.createConnection({
  host: "192.168.7.2",
  user: "root",
  password: ""
});

con.connect(function(err) {
  if (err) throw err;
  console.log("Connected!");
  /*Create a database named "mydb":*/
  con.query("CREATE DATABASE mydb", function (err, result) {
    if (err) throw err;
    console.log("Database created");
  });
});

But, when I try : node app.js I get : 

Error: connect ECONNREFUSED 192.168.7.2:3306
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1158:14)
    --------------------
    at Protocol._enqueue (/var/lib/cloud9/node_modules/mysql/lib/protocol/Protocol.js:145:48)
    at Protocol.handshake (/var/lib/cloud9/node_modules/mysql/lib/protocol/Protocol.js:52:23)
    at Connection.connect (/var/lib/cloud9/node_modules/mysql/lib/Connection.js:130:18)
    at Object.<anonymous> (/var/lib/cloud9/db.js:9:5)
    at Module._compile (internal/modules/cjs/loader.js:702:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
    at Module.load (internal/modules/cjs/loader.js:612:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
    at Function.Module._load (internal/modules/cjs/loader.js:543:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:744:10)

How to fix that ?

Thanks in advance.

Stuart Longland

unread,
Jun 26, 2018, 4:18:40 PM6/26/18
to beagl...@googlegroups.com
On 27/06/18 06:16, Ichrak Mansour wrote:
> Error: connect ECONNREFUSED 192.168.7.2:3306

>
> How to fix that ?

Tell `mysqld` on 192.168.7.2 to listen on the relevant interface.
You'll need to edit /etc/mysql/my.cnf (or its Windows equivalent if
192.168.7.2 is running Windows) to tell it to bind to that interface,
then re-start mysqld.

--
Stuart Longland (aka Redhatter, VK4MSL)

I haven't lost my mind...
...it's backed up on a tape somewhere.

Ichrak Mansour

unread,
Jun 26, 2018, 4:25:33 PM6/26/18
to beagl...@googlegroups.com
Thanks for your reply, but what I edit on  /etc/mysql/my.cnf  please ?
Knowing that the system on my BeagleBone is Debian 9.4.

--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/5b025773-9ce2-a91e-187b-15e2ee6ba37b%40longlandclan.id.au.
For more options, visit https://groups.google.com/d/optout.


--
    ICHRAK Mansour
Etudiante en ingénierie Téléinformatique
Université de Sousse - ISITCOM

Stuart Longland

unread,
Jun 26, 2018, 4:32:37 PM6/26/18
to beagl...@googlegroups.com
On 27/06/18 06:25, Ichrak Mansour wrote:
> Thanks for your reply, but what I edit on  /etc/mysql/my.cnf  please ?

The line that tells MySQL what IP address to bind to.

The file is usually documented with comments that tell you briefly what
each line does. Failing that, there's the documentation.

https://dev.mysql.com/doc/refman/8.0/en/option-files.html
https://dev.mysql.com/doc/refman/8.0/en/server-options.html#option_mysqld_bind-address

Ichrak Mansour

unread,
Jun 26, 2018, 4:52:07 PM6/26/18
to beagl...@googlegroups.com
But, my file /etc/mysql/my.cnf  is :

# The MariaDB configuration file
#
# The MariaDB/MySQL tools read configuration files in the following order:
# 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults,
# 2. "/etc/mysql/conf.d/*.cnf" to set global options.
# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options.
# 4. "~/.my.cnf" to set user-specific options.
#
# If the same option is defined multiple times, the last one will apply.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.

#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]

# Import all .cnf files from configuration directory
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/



--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Stuart Longland

unread,
Jun 26, 2018, 5:53:18 PM6/26/18
to beagl...@googlegroups.com
On 27/06/18 06:51, Ichrak Mansour wrote:
> But, my file /etc/mysql/my.cnf  is :
>
> # The MariaDB configuration file
> #
> # The MariaDB/MySQL tools read configuration files in the following order:
> # 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults,
> # 2. "/etc/mysql/conf.d/*.cnf" to set global options.
> # 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options.
> # 4. "~/.my.cnf" to set user-specific options.

… and it's telling you in the comments where to look for further
information. Perhaps the answer you're looking for is in
/etc/mysql/conf.d/ or /etc/mysql/mariadb.conf.d/ (#2 and #3 above)?

If you can picture those "!includedir" statements being replaced with
the contents of every *.cnf file contained in the directories they
reference, the place where `bind-address` goes should become clear.

This is a guess on my part, I haven't touched MySQL/MariaDB on Debian, I
use MariaDB on Gentoo for hosting my blog, but there they have a more
standard configuration file layout.

In addition, I tend to not connect to the database remotely via TCP/IP,
but instead communicate with it via Unix domain sockets which is the
default, as my database client and server are on the same machine.

Some MySQL clients will try Unix-domain sockets if you omit the host
name and port; I think the `mysql` shell client will do this by default
unless you give it a hostname and port to connect to on the command
line. The documentation for the client is what you need to reference here.

Your situation is different in that you have the BeagleBone running a
NodeJS application at one address, and a MySQL server on 192.168.7.2. I
have no idea what machine 192.168.7.2, it could be the BeagleBone, it
could be your workstation, it could be a tunnel to a cloud-based
instance of MySQL/MariaDB, I don't know, you haven't told us.

Research is about learning how to find the information, not begging for
it to be given to you. University is less about teaching you "how to
do", and more about "how to find out how to do".

Learning Linux in 1996, about 2 years before Google was founded and
before I knew what mailing lists, newsgroups or IRC were meant I had to
get cozy with `man`, The Linux Documentation Project, and a book shelf
with a limited selection of books on the topic.

Learning programming (BASIC) before that, again, was through books and
the help on the program: I did not know a single person who knew how to
write code, I had no one to ask. If I had waited for people to show me
directly how to do something, I'd be stuck playing games on MS-DOS right
now. (Or maybe their modern equivalents.)

We all start as novices, there's no shame in that, however if we only
learn what we are directly taught, then novices is where we stay.

Regards,
Reply all
Reply to author
Forward
0 new messages