Bobcares

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

by | Jan 23, 2019

I am getting “cannot connect to mysql server (10060)” error while trying to access my MySQL database remotely. 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 7 reasons for this error and how our Server Administrators fix them.

 

“Cannot connect to MySQL server (10060)” Error 

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.

Before we begin, let’s take a look at the impacts of this error:

  • When MySQL cannot be accessed, applications relying on the database will fail to function properly, leading to downtime. This can affect user experience and result in lost revenue for businesses.
  • Users and applications may be unable to retrieve or manipulate data, which can hinder business operations, reporting, and analytics.
  • Misconfigured MySQL servers that lead to connection issues may expose vulnerabilities, especially if remote access is not properly secured.

An Overview:

Causes & Fixes

1. Service Downtime

The MySQL service may not be running due to various issues such as heavy traffic, resource outages, or DDoS attacks.

Fix:

  • Check if MySQL is running with this command:

    netstat -plan | grep :3306

    This checks if the MySQL service is listening on port 3306.

  • Restart MySQL Service: If the service is not running, restart it using:

    sudo systemctl start mysql # For systemd
    sudo service mysql start # For sysvinit/upstart

Additionally, we can examine the MySQL error logs for any messages indicating why the service is down. The log file location can vary based on our configuration.

It is often found in /var/log/mysql/error.log or specified in your MySQL configuration file.

2. MySQL Configuration Issues

By default, MySQL may be configured to listen only for local connections (bind-address 127.0.0.1).

Fix:

  1. Open the MySQL configuration file located at /etc/mysql/my.cnf.
  2. Then, modify the bind-address line to:

    bind-address = 0.0.0.0

    Alternatively, we can comment out this line to allow connections from any address.

  3. After making changes, restart the service:

    sudo systemctl restart mysql

3. Firewall Restrictions

The firewall may block access to MySQL’s default port (3306).

Fix:

  • Temporarily disable the firewall to see if it resolves the issue. We can use Telnet to check port:

    telnet xx.xx.xx.xx 3306

    Remember to replace xx.xx.xx.xx with your server’s IP address.

  • If connectivity works without the firewall, adjust the rules to allow traffic on port 3306:
    • For UFW (Ubuntu):

      sudo ufw allow 3306

    • For Windows Firewall

      Add an exception for port 3306 through Control Panel settings.

4. Insufficient User Privileges

The MySQL user may lack permissions for remote access.

Fix:

  1. Log into MySQL and run:


    GRANT ALL ON *.* TO 'user'@'host_name' IDENTIFIED BY 'Password';
    FLUSH PRIVILEGES;

  2. Also, ensure that the remote host or IP is allowed access in the configuration.

5. Incorrect Connection String

Errors in the connection string (e.g., wrong server name, database name, username) can lead to connection failures.

Fix:

Check with the client for the correct connection string details. Furthermore, ensure that all components of the connection string (server name, database name, username, port) are accurate.

6. MySQL Server Configuration for Networking

The skip_networking system variable may be enabled, which prevents MySQL from accepting TCP/IP connections. This setting is often used for security reasons or during specific configurations.

Fix:

  1. Open the MySQL configuration file (usually located at /etc/mysql/my.cnf or /etc/my.cnf).
  2. Look for a line that says skip-networking and comment it out by adding a # at the beginning of the line, or remove it entirely.

    #skip-networking

  3. Then, restart the MySQL service to apply the new settings:

7. Long-running Transactions or Locks

Long-running transactions or locks can stall the MySQL server, causing it to become unresponsive and leading to connection timeouts.

Fix:

  1. Log into MySQL and run this command to check for active processes:

    SHOW PROCESSLIST;

  2. Look for any transactions that are in a “Locked” state or have been running for an unusually long time.
  3. If we identify a problematic process, we can terminate it using:

    KILL process_id;

  4. After killing any long-running transactions, monitor the server’s performance to ensure that it is responsive again.

Prevention Tips

  • Implement monitoring tools to track MySQL server performance and uptime while setting up alerts for service downtimes or connection errors.
  • Ensure the MySQL configuration allows remote connections by setting the bind-address appropriately and regularly reviewing settings like skip_networking.
  • Configure firewalls to permit traffic on MySQL’s default port (3306) and regularly test these rules for accessibility.
  • Regularly audit user permissions to ensure necessary privileges for remote access and use specific hostnames or IP addresses in user grants for enhanced security.
  • Implement connection pooling in applications to efficiently manage database connections and reduce the number of simultaneous connections made to the server.
  • Analyze slow queries with tools like EXPLAIN to optimize them and set appropriate timeout values to close idle connections automatically.
  • Schedule regular backups of your database to prevent data loss during downtime and keep MySQL updated to benefit from performance improvements and security enhancements.

[Need assistance with a different issue? Our team is available 24/7.]

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 7 reasons for this error and how our Support Engineers fix them.

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.

SEE SERVER ADMIN PLANS

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

6 Comments

  1. Deepanshu Suman

    I got this issue done.
    my firewall was not accepting port 3306.
    btw thanks I was in this issue from 1 day.

    Reply
    • Sijin George

      Hello Deepanshu,
      Happy to know that article helped you.

      Reply
  2. Sourabh

    Hello,
    I have similar issue. i am on Windows machine connecting to AWS-RDS. Getting similar error. I added Port 3306 to my Firewall(as both inbound and outbound rule), still no success. On AWS everything looks fine and I have added Inbound rule to security group (My IP). Can you please let me know what could be the issue?

    Reply
    • Hiba Razak

      Hi,
      Our Experts can help you with the issue, we’ll be happy to talk to you on chat (click on the icon at right-bottom).

      Reply
  3. Don

    Thank you for the great solution!

    Reply
    • Hiba Razak

      Thanks for the feedback.We are glad to know that it worked for you ? .

      Reply

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.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF