Error “cannot connect to mysql server (10060)” – Here’s how to fix it

I can’;t access my MySQL database remotely, it’;s throwing “cannot connect to mysql server (10060)”; error. Please help.

That was a recent support ticket received at our Server Management Services department where we manage our customer servers.

Website owners usually face this error due to firewall restrictions, MySQL service downtime, and more.

Today, we’;ll discuss the top 5 reasons for this error and how our Server Administrators fix them.

 

“Cannot connect to mysql server (10060)”; error –; Causes and Fixes

Customers usually receive this error when they try to access the MySQL server remotely.

Cannot connect to mysql server (10060)”; error means that the connection established failed because the host connected has failed to respond in time.

Let’;s now see the main reasons for this error and how our Server Experts fix them.

1) Service downtime

One of the common reasons for this error is MySQL service not running on the server. And, the reason for service downtime can be due to heavy traffic spikes, resource outages, DDoS attacks, and more.

 

How we fix?

So, our Support Engineers confirm whether the MySQL service is running in the server with the netstat command.

netstat -plan | grep :3306

 

If the service fails or doesn’;t respond, we’;ll kill the dead process and restart the service once again. In addition to that, we check the server logs to find the reason for the downtime and fix it permanently.

[Do you face intermittent MySQL downtime issues? Our experienced Server Administrators can fix this for you.]

 

2) MySQL configuration issues

By default, MySQL listens for connections only from localhost.

bind-address 127.0.0.1

 

So, if MySQL only supports local connections, users will receive “Cannot connect to mysql server (10060)”; error when establishing a remote MySQL connection.

 

How we fix?

Firstly, our MySQL experts check the MySQL configuration file /etc/mysql/my.cnf and confirm that MySQL remote access is enabled.

If not, we change the value of bind-address to 0.0.0.0 in /etc/mysql/my.cnf to accept all connections.

bind-address 0.0.0.0

 

Alternatively, we comment the bind-address parameter to enable remote connections. Similarly, in some cases, we give the bind-address as the IP address of the server where MySQL service listens.

bind-address database-IP

 

Here, MySQL will only listen connections to the server’;s IP. Most importantly, we restart the MySQL service to reflect the changes.

We always recommend taking the backup of this file before making any modifications. Because, a small typo error in this file can break your MySQL service.

[Do you want to enable Remote MySQL access on your server? Click here, one of our Server Admins can do this for you.]

 

3) Firewall restrictions

The next possible cause is MySQL port 3306 not opened in the server firewall. In other words, MySQL server can’;t accept any connection from the outside world due to firewall.

 

How we fix?

In such cases, our Support Engineers temporarily disable the firewall to determine whether the firewall is the culprit. Later, we check the MySQL port from /etc/mysql/my.cnf and use the telnet command to check the external connectivity to MySQL port.

telnet xx.xx.xx.xx 3306

 

If any firewall rules interfere with connectivity, we set the firewall rules to allow connections on the MySQL port.

For example, if MySQL server runs on Windows, we whitelist the MySQL port from Start > Control Panel > System & Security > Windows Firewall > Exceptions > Add Port.

Similarly, in Ubuntu servers we open the MySQL port in UFW firewall using the below command.

ufw allow 3306

4) No privileges to the remote user

Similarly, this error can occur if the MySQL user doesn’;t have enough privileges to remotely access the MySQL server.

In such cases, users will get an error “cannot connect to mysql server (10060)”;.

 

How we fix?

Here, our Hosting Engineers grant the user proper privileges to remotely access the database. Most importantly, we whitelist the remote hostname or IP address.

GRANT ALL ON *.* to 'user'@'host_name' identified by 'Password';
FLUSH PRIVILEGES;

 

Because, if a user connects as root user from a different machine, MySQL server can easily identify whether it’;s the root user in the local server or remote server.

For example in cPanel servers, we whitelist the remote host or IP address from cPanel > Databases > Remote MySQL .

[Worried about MySQL user permissions. One of our MySQL Experts can help you here.]

 

5) Wrong MySQL connection string

Last but not least, wrong connection string used to access the MySQL server remotely may lead to this error. A small typo in the MySQL server name, database name, username, port, etc. can block the connection to the MySQL server.

 

How we fix?

In such cases, our Support Experts get the MySQL connection string details from the client. After that, we configure an ODBC connection to the server. If that works, we compare the new string with the connection string. And, if any mismatch is noted, we’;ll correct it immediately.

Conclusion

In short, error “cannot connect to mysql server (10060)”; can happen due to firewall restrictions, MySQL configuration issues, MySQL service downtime, and more. Today, we’;ve discussed the top 5 reasons for this error and how our Support Engineers fix them.

The post Error “cannot connect to mysql server (10060)”; –; Here’;s how to fix it appeared first on Bobcares.