Common SQL Errors

MySQL Error 2011: CR_TCP_CONNECTION – How to Fix Connection Failures

Galaxy Team
August 5, 2025

MySQL client error 2011 (CR_TCP_CONNECTION) means the client library failed to open a TCP/IP socket to the MySQL server.

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 2011 (CR_TCP_CONNECTION)?

MySQL Error 2011: CR_TCP_CONNECTION occurs when the client cannot open a TCP/IP socket to the MySQL server. Check network reachability, host, port, and firewall rules, then retry the connection.

Error Highlights

Typical Error Message

%s via TCP/IP

Error Type

Connection Error

Language

MySQL

Symbol

CR_TCP_CONNECTION

Error Code

2011

SQL State

Explanation

Table of Contents

What is MySQL error 2011 (CR_TCP_CONNECTION)?

Error 2011 is raised by the MySQL client library when it cannot establish a TCP/IP socket to the target MySQL server. The error text usually appears as “hostname via TCP/IP.” The issue is purely connection-level and happens before authentication, so SQL syntax is not involved.

This error can surface in the mysql CLI, application drivers, or GUI tools. It blocks all database operations because no session can be opened.

Fixing it quickly is critical for uptime and data accessibility.

What causes this error?

Network reachability problems are the leading cause. If the client host cannot reach the server on the configured IP and port, the TCP handshake fails and MySQL returns CR_TCP_CONNECTION.

Incorrect connection parameters such as wrong hostname, port, or protocol can also trigger the error.

Firewalls, VPN misconfiguration, and host-based access controls routinely block traffic and surface as error 2011.

Resource exhaustion on the client or server side can block new sockets. Hitting the open-file limit, running out of ephemeral ports, or kernel-level connection tracking limits will all prevent a TCP socket from opening.

How do I fix MySQL Error 2011?

Start by validating the hostname and port. Use ping and telnet or nc to ensure the server is reachable.

Correct any typos in the connection string or DSN.

If the host is reachable, inspect firewall rules on the client, network, and server. Allow inbound traffic to the MySQL port (default 3306) and verify security groups or iptables rules.

Check server status. If mysqld is not listening on the expected port, start or restart the service. Confirm with netstat -tlnp or ss -ltn.

Investigate resource limits.

Raise ulimit -n on Linux if the open-file count is exhausted, and review net.ipv4.tcp_tw_reuse or nf_conntrack_max for high-traffic environments.

Common scenarios and solutions

Local development – When Docker containers map MySQL to a non-default port, update the connection string to match the exposed port.

Cloud deployments – Security groups may block 3306. Add an allow rule for the client subnet or use an SSH tunnel.

High-load servers – Many short-lived connections exhaust the TIME_WAIT bucket.

Enable connection pooling or adjust the TCP stack settings.

Best practices to avoid this error

Use connection pooling to minimize socket churn and lower the chance of hitting OS limits. Monitor open connections and file descriptors in Prometheus or similar tools.

Harden firewalls with least-privilege rules but document every allowed source. Automate configuration with IaC to prevent accidental blocks.

Store connection parameters in environment variables or a secrets manager to avoid typos.

Automate testing of connectivity in CI pipelines.

Related errors and solutions

CR_CONNECTION_ERROR (2002) – MySQL can’t connect through any protocol. Similar troubleshooting steps apply but includes Unix-socket checks.

CR_SERVER_GONE_ERROR (2006) – The server closed an established connection. Network stability and wait_timeout tuning resolve this.

CR_SERVER_LOST (2013) – Connection lost mid-query. Investigate timeouts, packet-size limits, and proxy resets.

.

Common Causes

Related Errors

FAQs

Does Error 2011 always mean MySQL is down?

No. It often indicates a network or firewall issue even when mysqld is running.

Can I fix CR_TCP_CONNECTION from SQL alone?

No. The error occurs before authentication. You must resolve network or OS-level problems first.

Will enabling SSL cause this error?

Incorrect SSL parameters can block the handshake, but the server must still be reachable. Most SSL errors appear after TCP connects.

How does Galaxy help avoid this error?

Galaxy stores validated connection profiles and pings the server before query execution, alerting you early if TCP connectivity fails.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo