LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   cannot connect to mysql database externally (https://www.linuxquestions.org/questions/linux-software-2/cannot-connect-to-mysql-database-externally-296514/)

lsimon4180 03-01-2005 08:59 PM

cannot connect to mysql database externally
 
Hi,

Im running Fedora 2 and Im trying to make a remote connect the mysql db running on the server but it keeps on saying:

Could not open connection to host on port 3306.

I am able to make a connection by doing telnet localhost 3306 on the server just not externally so i know its running.

I even added a rule in iptables:

iptables -A INPUT -p tcp --dport 3306 -j ACCEPT

also opened the port on my firewall.


Any suggestions?

Matir 03-01-2005 09:12 PM

Is the server listening on the external IP address as well as localhost? Many are configured only to listen to localhost.

lsimon4180 03-01-2005 09:25 PM

great question, how would i tell and if not how would i configure it?

lsimon4180 03-01-2005 09:47 PM

This is a copy of my my.cnf file:

[root@baguh etc]# vi my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

[mysql.server]
user=mysql
basedir=/var/lib

[safe_mysqld]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

I even tried putting in:

bind-address = 127.0.0.1
port = 3306

and tried my local net IP and external and restarted mysql but no dice

Matir 03-01-2005 09:54 PM

You do not want to bind it to 127.0.0.1. You can use "netstat" to see if it's listening on both 127.0.0.1 and (at least) *:3306.

lsimon4180 03-01-2005 10:01 PM

netstat shows nothing for the 3306, just a few httpd prcocess open.

nmap shows the following:

3306/tcp open mysql

I removed the bind-address and port variables from the file (like it was originally)

Thanks,

Lenny

lsimon4180 03-01-2005 10:04 PM

I try telnet locahost 3306 I get:

[root@xxxxx root]# telnet localhost 3306
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
(
3.23.58o>'Ht29e,

Then after about 5 sec the Connection closed by foreign host.

not sure if there is something else wrong.

When i telnet to it locally and then run netstat i see the established connection

Matir 03-02-2005 09:36 AM

The point is, you keep using localhost: but your problems are not with localhost, but external. You need to try connecting to the EXTERNAL ip of the machine, not 127.0.0.1.

lsimon4180 03-02-2005 09:46 AM

Oh it am trying to connect to my external IP from a different location but it just hangs on:

telnet external_IP 3306
Trying external_IP...

router, firewall are all allowing 3306 connections

Matir 03-02-2005 10:15 AM

But mysql is apparently not listening for external connections. Make sure there is no "skip-networking" entry in my.cnf. Also check for a bind-address = 127.0.0.1: there is one by default on most installs.

lsimon4180 03-02-2005 10:26 AM

THis is the contents of the my.cnf file:

[root@baguh etc]# vi my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

[mysql.server]
user=mysql
basedir=/var/lib

[safe_mysqld]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

Should I add the bind-address to my external IP or not?

berrance 03-02-2005 11:01 AM

make sure your router is forwarding the mysql port to the local ip address on which the sql server is hosted and set my sql to lisen on the local ip address as from your router it will be accessing the loacal ip

also can you access it localy? and does your isp block port 3306?

and just out of curiosity how come you want to access your sql data base externaly? if its on a web site the same server i hosting set the PHP script to use the local ip and not external as with apache sql and php it reads the sql serverside and not client side so ther is no point in having the port open if thats what you are doing

lsimon4180 03-02-2005 11:09 AM

It does work locally telnet localhost 3306 but not externally telnet ext_ip 3306, My ISP is not blocking that port, cuz i checked.

I have several customers that need enternal access (just temporarily) so I would like to know how to set this up. THey are using phpmaker and need to connect to the mysql server so they can work with phpmaker and there db.

the router is forwarding the port to the local IP of the server now how to I set mysql to listen to the local IP? do i add the following in the my.cnf file?

bind-address = 192.168.1.x

Thanks,

Lenny

NoStop 03-02-2005 11:34 AM

Have you considered using phpMyAdmin? That will give you an easy to use web access to your mysql databases, if all they need to do is edit, browse or backup their databases.

Cheers

lsimon4180 03-02-2005 11:39 AM

Yep, they and myself are using it right now, but the program that they are using phpmaker doesnt manage the db its connects to it and generates php code.

Thanks,

Lenny


All times are GMT -5. The time now is 12:25 AM.