I am trying to connect to my mySQL server through localhost on my dedicated server, but I keep getting the error:
Lost connection to MySQL server at 'reading initial communication packet', system error: 110
CODE:
<?php
$link = mysql_connect('localhost', '****', '****');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
I haven't configured a firewall, so all ports should be open. What do I need to do? I have already checked several other similar questions, but none of them solved my problem. I am not connecting remotely.
UPDATE
Okay I found the issue with the connection to the server (I was connecting twice). I am able to connect now to the server, but when I run any query, the server returns FALSE. I have used this code before and it has worked before, but now that I have changed servers, it is not working.
Thanks,
David
Open the MySQL Workbench Preferences. Check if the SSH Timeout and DBMS Timeout value is set to only a few seconds. Try to increase the default value of the connection timeouts. Save the settings, close the MySQL Workbench and reopen the connection to see if you are able to connect to the database.
Go to start- MySQL Installer-community and run again the installer as a re-configuration(you will be asked so). Once asked if you want make MySQL instance to run as a Windows service, check the box. In case would do not work, try unistalling and installing again, and check the box to run MySQL as Windows service.
mysql. connect_timeout tells PHP how long it should wait for a response from the MySQL server when it tries to connect. connect_timeout in MySQL configuration tells the MySQL server how long to wait for a connect packet from the client before responding with a Bad handshake error.
May be you are connecting to your db with different parameters
I had a similar error code of "110" on server A. Have never changed the credentials, etc on both server A and B. However, my issue was that one server is actually communicating via the MySQL port: 3306 of server B, and I have recently setup firewall on server B, to allow remote MySQL access from server A. Server A was trying to connect to the Server B MySQL port 3306 and webserver would just timeout, issuing the MySQL error code and line error on the code.
Solution that worked for me is:
sudo ufw status
Check if MySQL port is in the list, if not do this:
sudo ufw allow mysql
This will add the ip4 and ip6 rules into the firewall approved list.
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With