Ip4address not working for node-mysql connection ubuntu

匿名 (未验证) 提交于 2019-12-03 00:44:02

问题:

I am able to open phpmyadmin with both localhost as well as my IP4 address:

  1. http://localhost/phpmyadmin

  2. http://192.168.3.72/phpmyadmin

  3. http://127.0.0.1/phpmyadmin/

All the above Works

But when i try to apply IP4 address to this

var mysql      = require('mysql'); var connection = mysql.createConnection({   host     : 'localhost',   user     : 'me',   password : 'secret' }); 

Reference : https://github.com/felixge/node-mysql/#introduction

I get error as :

{ [Error: connect ECONNREFUSED]   code: 'ECONNREFUSED',   errno: 'ECONNREFUSED',   syscall: 'connect',   fatal: true } 

What am i doing wrong?

Ports which are used are:

Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address           Foreign Address         State       tcp        0      0 127.0.1.1:53            0.0.0.0:*               LISTEN      tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      tcp        0      0 127.0.0.1:28017         0.0.0.0:*               LISTEN      tcp        0      0 127.0.0.1:5939          0.0.0.0:*               LISTEN      tcp6       0      0 ::1:631                 :::*                    LISTEN      tcp6       0      0 :::80                   :::*                    LISTEN      

I tried with netstat -nlt | grep 3306

But i get blank output instead of :

mysqld  1046  mysql  10u  IPv4  5203  0t0  TCP  xxx.xxx.xxx.xxx:3306 (LISTEN) 

When tried with this post: Remote Connections Mysql Ubuntu

But when tried with : netstat -tulpn | grep :3306

I get output as:

tcp        0      0 192.168.3.72:3306       0.0.0.0:*               LISTEN      -   

Can anybody please assist with this...

回答1:

Did you try use "127.0.0.1" instead of "localhost"?



回答2:

You may be trying to connect to MySQL using the wrong port. To find out what port MySQL is listening to you can do this:

Windows (from MySQL):
mysql> SHOW GLOBAL VARIABLES LIKE 'PORT';

Unix:
netstat -tln

Once you have determined the correct port (which is 3306 by default), you can explicitly specify a port when you try to connect from Node:

var connection = mysql.createConnection({   host     : 'localhost',   user     : 'me',   password : 'secret',   port: 3306 }); 


回答3:

I finally was able to solve the problem :-)

  1. I logged in as root using sudo su
  2. Edited subl /etc/mysql/my.cnf & Replace bind-address with my IP4 address
  3. Run : service mysql restart

Finally it gave me result as:

mysql stop/waiting mysql start/running, process 12210 

And now i am able to login successfully using IP4 address from external sources.

Thanks for all :-)



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!