问题
I am able to open phpmyadmin with both localhost as well as my IP4 address:
http://localhost/phpmyadmin
http://192.168.3.72/phpmyadmin
- 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 :-)
- I logged in as root using
sudo su
- Edited
subl /etc/mysql/my.cnf
& Replace bind-address with my IP4 address - 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 :-)
来源:https://stackoverflow.com/questions/30367380/ip4address-not-working-for-node-mysql-connection-ubuntu