Error: connect ECONNREFUSED

I try to execute nodejs with mySQL with the code below :

var mysql = require(‘mysql’);

var con = mysql.createConnection({
host: “”,
user: “root”,
password: “”

con.connect(function(err) {
if (err) throw err;
/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
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1158:14)

Error: connect ECONNREFUSED

How to fix that ?

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

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.

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.

But, my file /etc/mysql/my.cnf is :

The MariaDB configuration file

… 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 I
have no idea what machine, 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.