Programmers learn & share
0 votes

Problem :

I am new to MySQL and facing following error message while trying to connect my DB:

"Lost connection to MySQL server at 'reading initial communication packet, system error: 0"

If I am trying to connect my MySQL DB to the localhost then everything is working as it should. But when I am trying to connect my MySQL DB with my live IP address like following one, it is giving me the above mentioned error:

mysql_connect("", "xxxx", "xxxxx") or die(mysql_error());

Does anyone ever faced such issue? Also please let me know the solution for this issue if possible.

by (6.9k points)   | 56 views

1 Answer

0 votes

Solution :

I had faced the same issue in the recent past and I resolved my issue by following below mentioned simple steps:

1) Allow the remote connecion to MySQL.Edit file:

>sudo nano /etc/mysql/my.cnf

Comment below line:

#bind-address       =

Restart the MySQL:

>sudo service mysql restart

2) Create new user for remote connection.

>mysql -uroot -p
CREATE USER 'developer'@'localhost' IDENTIFIED BY 'dev_password';
CREATE USER 'developer'@'%' IDENTIFIED BY 'dev_password';
GRANT ALL ON *.* TO 'developer'@'localhost';
GRANT ALL ON *.* TO 'developer'@'%';

3) In my case I needed to connect remotely from my Windows box to VirtualBox machine having Ubuntu. So I needed to allow port 3306 in iptables as follows:

>iptables -A INPUT -i eth0 -p tcp -m tcp --dport 3306 -j ACCEPT
by (36.1k points)  
2,245 questions
2,807 answers
241 users