While connecting to a MySQL database, you might run into this error:

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

There seems to be a problem with the firewall blocking outside connection. What you need to do is to check the firewall rules and see if it’s blocking any MySQL connection.

If the firewall is not the issue, then go over the list below and see if you have any of it:

  1. Check that MySQL is running on server IP

  2. Check that MySQL is listening on port 3306 (note: 3306 is the default, but this can be changed)

  3. Check the user has rights to connect to the server IP from your address

  4. Make sure you are both providing a password if needed and using the correct password for connecting from the host address you’re connecting from

Most of the time, the case is that MySQL only listens on the localhost and does not accept remote connections. So you cannot connect from outside.

You need to check the bind-address variable in the my.cnf file. It defaults to localhost hence localhost works but not connection from other hosts.

So to make sure MySQL listens on all addresses, comment out the line:

#bind-address = 127.0.0.1

Then restart the server:

sudo service mysql restart

Need a good GUI tool for databases? TablePlus provides a native client that allows you to access and manage Oracle, MySQL, SQL Server, PostgreSQL, and many other databases simultaneously using an intuitive and powerful graphical interface.

Download TablePlus for Mac.

Not on Mac? Download TablePlus for Windows.

On Linux? Download TablePlus for Linux

Need a quick edit on the go? Download TablePlus for iOS

TablePlus in Dark mode