MySQL Error 2005 occurs when the MySQL client cannot resolve or connect to the specified hostname. Common causes include typos in the hostname, incorrect hostname format (including protocol), DNS resolution failures, network connectivity issues, or the port being included in the hostname. Fixing requires verifying the hostname spelling, using correct connection syntax, and testing network connectivity.
MySQL Error 2005 (HY000) is a client connection error that indicates the MySQL client failed to resolve or reach the specified MySQL server host. This error occurs during the initial connection phase before any authentication is attempted. The error means that either: (1) the hostname is not a valid hostname format, (2) the hostname cannot be resolved to an IP address by the DNS system, (3) the resolved IP address is not reachable from the client, or (4) the hostname syntax itself is malformed. Unlike authentication errors (Error 1045: Access denied) or connection refused errors (Error 2003: Cannot connect), Error 2005 means the client could not even identify where the server is. This is typically a configuration or environment issue rather than a server problem—the server may not even be receiving the connection attempt.
The most common cause is a typo or incorrect format. Ensure the hostname is exact and does not include protocols or ports.
# Correct format examples:
mysql -h localhost -u root -p
mysql -h 127.0.0.1 -u root -p
mysql -h db.example.com -u root -p
mysql -h mysql-server -u root -p # Docker container name
# INCORRECT formats that cause Error 2005:
mysql -h http://localhost -u root -p # ❌ Do not include http://
mysql -h localhost:3306 -u root -p # ❌ Port in hostname
mysql -h "localhost 3306" -u root -p # ❌ Space instead of colon
mysql -h local host -u root -p # ❌ Space in hostname
mysql -h localhost. -u root -p # ❌ Trailing dotDouble-check your connection command or connection string configuration.
When connecting via command line, always separate the hostname and port using distinct options, not a combined string.
# Correct: separate -h and -P options
mysql -h db.example.com -P 3306 -u root -p
# Correct: default port (3306) does not need -P
mysql -h db.example.com -u root -p
# If using non-default port:
mysql -h 192.168.1.10 -P 3307 -u root -p
# For TCP socket connections (Windows):
mysql -h . -u root -p # Dot means localhost via TCPIf you must use a connection string format (e.g., in code), the syntax is "host:port", but ensure your client library is parsing it correctly.
If using a domain name (not localhost or IP), verify DNS can resolve it.
# Linux/Mac: Use nslookup or dig
nslookup db.example.com
dig db.example.com
host db.example.com
# Windows: Use nslookup
nslookup db.example.com
# All platforms: Use ping to test both resolution and reachability
ping db.example.com
# If nslookup returns "server can't find db.example.com":
# - Hostname does not exist in DNS
# - DNS server is wrong
# - Network has no DNS connectivityIf DNS resolution fails, contact your infrastructure team or DNS provider. For local testing, add the hostname to your hosts file instead:
# Linux/Mac: Edit /etc/hosts
127.0.0.1 db.local
# Windows: Edit C:\Windows\System32\drivers\etc\hosts
127.0.0.1 db.local
# Then connect:
mysql -h db.local -u root -pConfirm the client can reach the IP address where MySQL is running.
# Ping the resolved IP:
ping 203.0.113.45
# Check if MySQL port (3306) is reachable:
telnet 203.0.113.45 3306
# or using netcat:
nc -zv 203.0.113.45 3306
# On Mac/Linux, use bash timeout to avoid hanging:
timeout 5 bash -c "cat < /dev/null > /dev/tcp/203.0.113.45/3306" && echo "Port open" || echo "Port closed"If these network tests fail:
- The MySQL server is not running at that IP
- A firewall is blocking port 3306
- The IP address is not routable from your network
- For cloud databases (AWS RDS, Azure), the security group/NSG rules do not allow your IP
Work with your network or cloud provider to restore connectivity.
In containerized environments, use the service name (not localhost) to connect between containers.
# Docker Compose: use service name from docker-compose.yml
mysql -h mysql -u root -p # "mysql" is the service name
# Docker (bridged network): use container name or IP
mysql -h mysql-container -u root -p
# Kubernetes: use the service DNS name
mysql -h mysql-service.default.svc.cluster.local -u root -p
# Find your service IP:
kubectl get svcNever use 127.0.0.1 or localhost in Docker if MySQL runs in a separate container. Use the container or service name instead.
Cloud-managed databases (AWS RDS, Azure MySQL, Google Cloud SQL) require proper endpoint configuration.
# AWS RDS endpoint example:
mysql -h my-database.c9akciq32.us-east-1.rds.amazonaws.com -u admin -p
# Azure endpoint example:
mysql -h myserver.mysql.database.azure.com -u admin@myserver -p
# Verify the endpoint in your cloud console:
# AWS: RDS Dashboard > Databases > Endpoint
# Azure: MySQL Server > Overview > Server name
# Google Cloud: Cloud SQL Instances > Connection name
# Ensure your client IP is in the security group (AWS) or firewall rules (Azure):
# AWS: RDS > Security group > Inbound rules > MYSQL/Aurora 3306
# Azure: Connection security > Add current client IPWait 1-2 minutes after creating a database before attempting to connect, as DNS propagation takes time. Also verify the database status is "available" or "running" in the cloud console.
If this error occurs in an application (Node.js, Python, PHP, etc.), verify the connection config is correct.
// Node.js / mysql2 - CORRECT
const connection = mysql.createConnection({
host: 'db.example.com',
user: 'root',
password: 'secret',
database: 'mydb'
});
// INCORRECT - includes port in host
const connection = mysql.createConnection({
host: 'db.example.com:3306', // ❌ Error 2005
user: 'root'
});
// INCORRECT - includes protocol
const connection = mysql.createConnection({
host: 'https://db.example.com', // ❌ Error 2005
user: 'root'
});
// CORRECT - port separate
const connection = mysql.createConnection({
host: 'db.example.com',
port: 3306,
user: 'root',
password: 'secret',
database: 'mydb'
});Check your environment variables, config files, or connection strings for typos and correct format.
Error 2005 is frequently the result of incorrect hostname syntax rather than server problems. MySQL expects a bare hostname or IP address without protocol prefixes, port numbers, or spaces. The distinction between Error 2005 (unknown host) and Error 2003 (connection refused) is important: Error 2005 means the client never reached the server, while Error 2003 means the client reached an IP but the server was not listening. This helps narrow down whether the issue is DNS/network or server-specific.
In multi-region cloud deployments, ensure you are using the correct regional endpoint. For example, AWS RDS endpoints are region-specific (us-east-1.rds.amazonaws.com vs eu-west-1.rds.amazonaws.com). Using the wrong region will cause DNS to return the wrong IP (or not resolve) and trigger Error 2005.
For password-containing connection strings, special characters like "@" in the password can be misinterpreted as the "user@host" separator. URL-encode the password (e.g., "p%40ssw0rd" for "p@ssw0rd") if embedding it in a connection URI.
When debugging Docker networking, remember that containers on custom networks can reach each other by service name, but containers on the bridge network need to use the container's IP or be linked. Use docker network inspect to verify connectivity and docker inspect <container> to check the IP.
For DNS-heavy scenarios, consider adding retry logic and fallback to IP addresses in your connection code, or use a connection pooling library that handles transient DNS failures gracefully.
EE_WRITE (3): Error writing file
How to fix "EE_WRITE (3): Error writing file" in MySQL
CR_PARAMS_NOT_BOUND (2031): No data supplied for parameters
How to fix "CR_PARAMS_NOT_BOUND (2031): No data supplied for parameters" in MySQL
CR_DNS_SRV_LOOKUP_FAILED (2070): DNS SRV lookup failed
How to fix "CR_DNS_SRV_LOOKUP_FAILED (2070): DNS SRV lookup failed" in MySQL
ERROR 1146: Table 'database.table' doesn't exist
How to fix "ERROR 1146: Table doesn't exist" in MySQL
ERROR 1040: Too many connections
How to fix "ERROR 1040: Too many connections" in MySQL