LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Lost connection to MySQL server at reading.... (https://www.linuxquestions.org/questions/linux-server-73/lost-connection-to-mysql-server-at-reading-733556/)

jonaskellens 06-17-2009 04:37 AM

Lost connection to MySQL server at reading....
 
phpMyAdmin - Error :
2013 - Lost connection to MySQL server at 'reading initial communication packet'

I have an apache webserver running on a Fedora 10, with phpMyAdmin installed.
I have a mysql server running on another Fedora 10 system.

I have edited /etc/phpMyAdmin/config.inc.php with the IP-address of my mysql-server, my root-user and password.

When I enter http://ip-address-of-webserver/phpMyAdmin and I log in with my root - credential, I get the above error.

PhpMyAdmin.conf accepts connections from the clients connected to the LAN. But I don't think the issue is situated here.

This is the configuration of my mysql-server :
Code:

[root@database database]# hostname
database.jocan.local

I added the following to /etc/my.cnf :
Code:

bind-address=127.0.0.1
This is the output of netstat -al
Code:

tcp        0      0 localhost.localdomain:mysql *:*                        LISTEN
Do I have some kind of firewall issue on my webserver or database-server ?? Don't think I need to open port 3306 on my webserver, or do I ?

EricTRA 06-17-2009 05:15 AM

Hi,

You state that you have changed your phpmyadmin config to contain the IP of your MySQL server. What IP have you put there? The localhost IP? Because your MySQL config (bind-address) makes it only listen on the localhost IP 127.0.0.1.

If you want to access mysql with phpmyadmin from another pc using the webbrowser (instead of only on the linuxbox) then you'll have to change the bind-address on the my.cnf file and change your phpmyadmin config also.

Also if you have a firewall enabled you should configure it to allow communication on port 3306 if you want to access your MySQL using another tool like MySQL Administrator.

That should do the trick.

jonaskellens 06-17-2009 05:45 AM

Quote:

Originally Posted by EricTRA (Post 3576913)
You state that you have changed your phpmyadmin config to contain the IP of your MySQL server. What IP have you put there? The localhost IP? Because your MySQL config (bind-address) makes it only listen on the localhost IP 127.0.0.1.

As IP-address of my mysql-server I have put 192.168.2.4.
My webserver has IP-address 192.168.2.3

What IP-address should my MySQL-server listen to in stead of 127.0.0.1 ??
Should it listen to 192.168.2.4 ??

Quote:

Also if you have a firewall enabled you should configure it to allow communication on port 3306 if you want to access your MySQL using another tool like MySQL Administrator.
I need to open up port 3306 on my webserver too ???

EricTRA 06-17-2009 05:53 AM

The bind-address of your MySQL server should be 192.168.2.4 in the my.cnf file if you want to connect to that IP from the webserver. Restart the MySQL daemon in order to activate it. The netstat -al command should list that mysql is listening on the correct IP and not only on localhost. localhost setting only applies if you are running MySQL and your webserver on the same server.

In your phpadminconfig you also should put that IP for the MySQL. On the webserver, if you have a firewall configured, you normally don't have to change anything since the communication from webserver to mysql is outgoing and hence not blocked. If however you also have a firewall installed on the MySQL server, than there you should make sure that connection to it on port 3306 is possible for example with telnet 192.168.2.4 3306, which will show if connection is possible. It will not give you any reasonable data or options but only will show if the port is accessible.

jonaskellens 06-18-2009 04:22 AM

Quote:

Originally Posted by EricTRA (Post 3576943)
In your phpadminconfig you also should put that IP for the MySQL. On the webserver, if you have a firewall configured, you normally don't have to change anything since the communication from webserver to mysql is outgoing and hence not blocked. If however you also have a firewall installed on the MySQL server, than there you should make sure that connection to it on port 3306 is possible for example with telnet 192.168.2.4 3306, which will show if connection is possible. It will not give you any reasonable data or options but only will show if the port is accessible.

Opening port 3306 on my MySQL-server still gives me the error :
2013 - Lost Connection to MySQL-server at 'reading initial communication packet', system error 113

Shutting down the firewall on my MySQL-server makes this error disappear. Then I get :
Host '192.168.2.3' is not allowed to connect to this MySQL-server'.
So I need to edit some accept/deny-rules somewhere, like I did with my apache.

I'm a bit confused about port 3306 here...

/usr/bin/mysql_config --port returns '0'

EricTRA 06-18-2009 04:38 AM

Quote:

Originally Posted by jonaskellens (Post 3578088)
Opening port 3306 on my MySQL-server still gives me the error :
2013 - Lost Connection to MySQL-server at 'reading initial communication packet', system error 113

Shutting down the firewall on my MySQL-server makes this error disappear. Then I get :
Host '192.168.2.3' is not allowed to connect to this MySQL-server'.
So I need to edit some accept/deny-rules somewhere, like I did with my apache.

I'm a bit confused about port 3306 here...

Hi,

Probably you'll have to put the 'webserver' in the /etc/hosts.allow file in order to allow it to connect to the mysql server. Thing is that the webserver can connect to the mysql on the correct port but once connection is established the mysql server is going to check if the webserver is allowed access. If the webserver is not listed as allowed host then connection gets disconnected which is a normal security operation. Just changing the hosts.allow file (explanation inside the file) should do the trick if you don't have another firewall configured. If so then depending on that firewall you might also have to configure it that it should trust your webserver.

Kind regards,

Eric Van Steenbergen

jonaskellens 06-18-2009 05:18 AM

I've put the following in my /etc/hosts.allow
Code:

mysqld: 192.168.2.3
but still I get the error that '192.168.2.3 is not allowed to connect to MySQL-server.
My iptables is turned off.

When my iptables is turned on I still get the 'lost connection'-error. I have put the extra line in /etc/my.cnf :
Code:

port=3306
Code:

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address              Foreign Address            State     
tcp        0      0 192.168.2.4:mysql          *:*                        LISTEN


jonaskellens 06-18-2009 06:39 AM

Succeeded in accessing my MySQL-server.

First off all I had opened port 3306/UDP which had to be 3306/TCP as I connect over a TCP-connection...

Second I created a new user in the mysql.user DB with the permissions needed and with the 'Host'-value being the IP-address of my webserver.

Thx for all the reply and feedback EricTRA !

EricTRA 06-18-2009 07:05 AM

Quote:

Originally Posted by jonaskellens (Post 3578121)
I've put the following in my /etc/hosts.allow
Code:

mysqld: 192.168.2.3
but still I get the error that '192.168.2.3 is not allowed to connect to MySQL-server.
My iptables is turned off.

When my iptables is turned on I still get the 'lost connection'-error. I have put the extra line in /etc/my.cnf :
Code:

port=3306
Code:

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address              Foreign Address            State     
tcp        0      0 192.168.2.4:mysql          *:*                        LISTEN


Did you have to put the port = 3306 in the my.cnf? That strikes me as very strange since it's in there by default installation.

Can you telnet from the webserver to the mysql server?

Code:

telnet mysqlserverip 3306
The output would be garbled but that way you'll know that the mysql server is listening and accepting connections.

EricTRA 06-18-2009 07:07 AM

Quote:

Originally Posted by jonaskellens (Post 3578209)
Succeeded in accessing my MySQL-server.

First off all I had opened port 3306/UDP which had to be 3306/TCP as I connect over a TCP-connection...

Second I created a new user in the mysql.user DB with the permissions needed and with the 'Host'-value being the IP-address of my webserver.

Thx for all the reply and feedback EricTRA !

Yeah, great work! As always I forgot to look at the basics (Port being on UDP instead of TCP).

Glad it works. And you're welcome.


All times are GMT -5. The time now is 06:50 PM.