Connecting to MySQL Server: Understanding Error 111
Connecting to a MySQL server from a remote machine can sometimes result in an "Error 111: Can't connect to MySQL server" message. This error indicates that the client cannot establish a connection with the server.
Difference between localhost/127.0.0.1 and External IP
In the given scenario, the MySQL server is only listening on the localhost interface (127.0.0.1). When using localhost or 127.0.0.1, the client and server are essentially on the same machine, allowing for direct communication.
On the other hand, connecting to the server's external IP address (192.168.1.100) requires the client to establish a connection over the network. If the MySQL server is not configured to listen on all interfaces, it will only accept connections from the local machine.
Solution
To resolve this issue, you need to edit the MySQL configuration file (my.cnf) and uncomment the following lines:
bind-address = 127.0.0.1
By uncommenting these lines, you are allowing the MySQL server to listen on all interfaces. Once this is done, restart MySQL:
sudo service mysql restart
Now, you should be able to connect to the MySQL server from both the local and remote machines without encountering Error 111.
The above is the detailed content of Why Am I Getting MySQL Error 111: Can't Connect to MySQL Server?. For more information, please follow other related articles on the PHP Chinese website!