Common SQL Errors

MySQL Error 2005: CR_UNKNOWN_HOST - How to Fix and Prevent

Galaxy Team
August 5, 2025

The client cannot resolve the hostname in the connection string, so the MySQL server remains unreachable.

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 code 2005?

MySQL Error 2005: CR_UNKNOWN_HOST means the hostname in your connection string cannot be resolved. Verify DNS, hosts file, or use the correct IP address to connect successfully.

Error Highlights

Typical Error Message

Unknown MySQL server host '%s' (%d)

Error Type

Connection Error

Language

MySQL

Symbol

CR_UNKNOWN_HOST

Error Code

2005

SQL State

Explanation

Table of Contents

What does “Unknown MySQL server host” mean?

MySQL raises Error 2005 (CR_UNKNOWN_HOST) when the client library cannot translate the host string you passed to a valid IP address. The TCP connection never starts, so authentication and SQL execution do not occur.

The message includes the failing host value and a system errno.

These details point to DNS or networking layers, not the MySQL daemon itself.

When does Error 2005 usually appear?

It appears immediately after a mysql, mysqldump, JDBC, or Python connector call that contains a typo, stale DNS entry, or blocked outbound port 3306.

Cloud VMs with custom DNS or VPNs often surface the issue.

Local development can also trigger the error if /etc/hosts or Windows hosts entries are missing for aliases like mysql.local.

How do I fix MySQL Error 2005?

Start by pinging the hostname from the same machine. If ping fails, check DNS or the hosts file. If ping succeeds, verify your MySQL port and firewall.

Finally, replace the hostname with a verified IP address to isolate name-resolution problems.

Updating connection strings in ORM configs, Docker compose files, or Kubernetes Secrets prevents the error across deployments.

Common scenarios and solutions

In Docker, the service name must match the container’s network alias.

Using “localhost” inside one container fails; use the service alias instead.

For AWS RDS, ensure the VPC DNS resolver is enabled and that your security group allows outbound DNS requests (port 53) and MySQL (3306).

Best practices to avoid CR_UNKNOWN_HOST

Store hostnames in environment variables managed by your CI/CD. Validate them during health checks.

Monitor DNS latency and failures with tools like dig or nslookup inside your application container.

With Galaxy, test queries directly in the editor; failed connections surface instantly, letting you correct host settings before committing code.

.

Common Causes

Related Errors

FAQs

Is CR_UNKNOWN_HOST a server or client error?

It is a client-side networking error; the MySQL server never receives the connection request.

Can I bypass DNS to fix the error?

Yes. Use the server’s IP address directly or add a hosts file entry. This instantly proves whether DNS is the culprit.

Does MySQL version matter?

No. Error 2005 is generated by the libmysql client, so it appears across all server versions when name resolution fails.

How does Galaxy help?

Galaxy shows connection failures inline and lets you test alternate hosts quickly, reducing debugging time.

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