Im trying to use node-red-node-mysql to connect to MariaDB on the same server using localhost.
The node does not connect, but gives the error:
Error: connect ECONNREFUSED 127.0.0.1:3306
I'm sure I have missed something simple, but I have been searching for a while now.
I have tried with root user and also created a user called node-red
I have set plugin=mysql_native_password on the node-red user
I found what I think is the config file under: /etc/mysql/mariadb.conf.d/50-server.cnf
#
# * Basic Settings
#
user = mysql
pid-file = /run/mysqld/mysqld.pid
socket = /run/mysqld/mysqld.sock
#port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
#skip-external-locking
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 127.0.0.1
Some people had problems with the bind address when connecting from a remote machine, but my node-red server and the db are on the same machine, so am I correct in assuming I can leave it as is?
Server version: MariaDB version 10.3.34
Ubuntu 20.04.1
Hi Colin. Thanks for getting back to me so quickly.
Node-Red and Mariadb are both running locally on a Dell Optiplex with Ubuntu 20. I am not using Docker. I installed using the raspberry Pi install script from the getting started page of node-red docs.
I am working remotely, over a VPN from a windows machine.
I can browse to the node-red flows editor using chrome.
I am able to access the db using the command line (via putty ssh).
Here is the output of some command line interactions with the db. You may recognise some table names from the getting started section of MariaDB docs. There is nothing important in the DB at this stage:
michael@linbox01:~$ mysql -u node_red -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 23
Server version: 10.3.34-MariaDB-0ubuntu0.20.04.1 Ubuntu 20.04
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> use tests;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [tests]> show tables;
+-----------------+
| Tables_in_tests |
+-----------------+
| authors |
| books |
| series |
+-----------------+
3 rows in set (0.001 sec)
Thanks Random. I got it to work
The KnowledgeBase link you posed allowed me to actually find my config file:
/etc/mysql/mariadb.conf.d/50-server.cnf
The bind address was not my problem, as I am connecting from the same machine, so 127.0.0.1 was fine for me. However, while I was trying your suggestion, I noticed that the line in the config file that sets the port number was commented out.
ie. #port = 3306
I have no idea why this would be the default, but I removed the #, saved the config file and rebooted.
Now magically, my node connects!
Many thanks!
Don't know if the solutions were 2 different ways of solving the same issue (bind address or uncommenting port line), as in my config the #port = 3306 is also present.