• Register
0 votes
65 views

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("202.131.xxx.106:xxxx", "xxxx", "xxxxx") or die(mysql_error());

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

6.9k points

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       = 127.0.0.1

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
36.1k points

Related questions

0 votes
1 answer 19 views
19 views
Problem: I am interested in learning MySQL. Currently I am facing the following error if I tried to add the index to my table using the MySQL Workbench: “Error Code: 2013. Lost connection to MySQL server during query.” I also noticed that above error appears only when I try to run long query. I want to know the away to increase my timeout value?
asked Jul 27 Raphael Pacheco 2.3k points
0 votes
1 answer 23 views
23 views
Problem : I have a Stored procedure like below: CREATE PROCEDURE MyProG() BEGIN SELECT * FROM `hs_hr_employee_leave_quota`; END But it gives me the below error: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3 What does this error mean? What is wrong with my line number 2?
asked Jan 30 jwilliam 3.9k points
0 votes
1 answer 99 views
99 views
Problem : I am getting following error in my error log file [18-Nov-2019 19:09:55 UTC] PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [1040] Too many connections' in /home/root/products/db.php:2 Stack trace: /home/ ... ', 'root', '**somePassword**'); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
asked Nov 20, 2019 peterlaw 6.9k points
0 votes
1 answer 8 views
0 votes
1 answer 74 views
74 views
Problem : I am new to MySQL driver. I am trying to connect to the database server using MySQL driver but I always face the below error. A Database Error Occurred Unable to connect to your database server using the provided settings. Filename: core/Loader.php Line Number: 232 Please ... I am trying to fix above error from past couple of days but unable to find any solution on it. How can I fix it?
asked Feb 25 mphil 2.3k points