Bobcares

Lost Connection to MySQL Server at Reading Initial Communication Packet

by | May 7, 2022

Lost connection to MySQL server at reading initial communication packet, is an error we get while connecting to a MySQL database. As part of our Server management services, Bobcares provides solutions for every query.

Let’s take a look at how our Support team handled this situation.

Lost connection to MySQL server at ‘reading initial communication packet

While connecting to a MySQL database, we might run into this error: Lost connection to MySQL server at reading initial communication packet, system error: 0

Lost Connection to MySQL Server at Reading Initial Communication Packet

There appears to be an issue with the firewall, which is preventing outside connections. We should check the firewall rules to see if they are blocking any MySQL connections.

If the firewall isn’t the problem, check the list below to see if we have any of the following:

  1. Verify that MySQL is running on the server’s IP address.
  2. Then, Make sure MySQL is listening on port 3306.
  3. Ensure that the user has permission to connect to the server IP.
  4. Make sure we’re using the correct password for connecting from the host address we’re connecting from if one is required.

Most of the time, MySQL only listens on localhost and does not accept connections from other computers. As a result, we can’t connect from the outside leading to the Lost Connection to MySQL Server error.

In the my.cnf file, look at the bind-address variable. Because it defaults to localhost, only connections from that host will work.

  • Comment out the line: to ensure MySQL listens on all addresses. #bind-address = 127.0.0.1
  • Then restart the server as follows: sudo service mysql restart
  • GRANT ALL PRIVILEGES ON ourDB.* TO 'username'@'OUR_APPLICATION_IP' IDENTIFIED BY 'OUR_PASSWORD' WITH GRANT OPTION;

If we still get the error, then:

  1. Allow applications through the Windows Firewall.
  2. The path to mysql is typically C:/Program Files (x86)/MySQL/bin/mysql, so we’ll need to add it to the list.
  3. Click Apply after marking both private and public networks.

If the IP address is blocked by Firewalld. Use the following commands to grant access: firewall-cmd --permanent --zone=trusted --add-source=OUR_IP/32 firewall-cmd --permanent --zone=trusted --add-port=3306/tcp firewall-cmd --reload

Another solution for the Lost Connection to MySQL Server error is to choose + to add a new connection in the workbench and enter the following information:

  • TCP/IP over SSH is the connection method.
  • xxx.xxx.xx.xx:xx (replace xx with remote SSH server IP and port(optional)) is the SSH Hostname
  • Enter the SSH username
  • At the prompt, we can set a password.
  • MYSQL Localhost or 127.0.0.1 is the hostname.
  • Port:3306 MYSQL Server
  • At the prompt, we can enter a password or add a new one.

Then, check the connection. If it is successful, click OK. Also, to ensure MySQL Server connections are not denied:

1. Check /etc/hosts.deny and make sure it does not contain:

ALL: ALL: DENY
mysqld: ALL: DENY

2. If needed, add the following to /etc/hosts.allow:

makefile

mysqld: ALL

3. Or to allow only specific networks, use:

makefile

mysqld: 192.168.1.0/255.255.255.0

4. Note that when connecting to MySQL Server:

  • localhost uses the UNIX socket.
  • 127.0.0.1 uses TCP/IP networking.

These two are not interchangeable.

If nothing else works, flush the privileges. mysql> FLUSH PRIVILEGES;

[Looking for a solution to another query? We are just a click away.]

Conclusion

To sum up, our Support team was successful in resolving the error: Lost connection to MySQL server at reading initial communication packet with the above steps

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.