Error
Error Code: 2005

MySQL Error 2005: Unknown Host Connection Failure

📦 MySQL
📋

Description

Error 2005 indicates that your MySQL client application failed to resolve or connect to the specified database server host. This typically occurs when the hostname provided in the connection string is incorrect, the server is unreachable, or there's a network configuration issue preventing name resolution.
💬

Error Message

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

Known Causes

4 known causes
⚠️
Incorrect Hostname or IP
The hostname or IP address specified in your client connection string is misspelled, wrong, or does not correspond to the actual MySQL server.
⚠️
DNS Resolution Failure
The system cannot translate the provided hostname into an IP address, often due to an issue with DNS servers, local host files, or network configuration.
⚠️
MySQL Server Offline
The MySQL server instance on the target host is not running or has crashed, making it unresponsive to connection attempts.
⚠️
Network Firewall Block
A firewall (either on the client, server, or network path) is blocking the connection attempt to the MySQL server's port.
🛠️

Solutions

3 solutions available

1. Verify MySQL Server Hostname or IP Address easy

Ensure the hostname or IP address specified in your connection string is correct and resolvable.

1
Double-check the hostname or IP address used in your application's or client's MySQL connection configuration. Common typos include incorrect characters, transposed digits, or using a local hostname that isn't accessible from the client machine.
2
From the client machine attempting to connect, try to ping the MySQL server's hostname or IP address. This will verify basic network reachability.
ping your_mysql_host_or_ip
3
If pinging by hostname fails but by IP succeeds, it indicates a DNS resolution issue. Update your DNS records or use the IP address directly in your connection string as a temporary workaround.

2. Check MySQL Server Status and Network Accessibility medium

Confirm the MySQL server is running and accessible on the specified port.

1
Log in to the MySQL server machine and verify that the MySQL service is running. The command to check the service status varies by operating system.
# On systems using systemd (e.g., Ubuntu 15.04+, CentOS 7+)
systemctl status mysql

# On older systems using SysVinit (e.g., Ubuntu 14.04, CentOS 6)
service mysql status
2
Ensure that the MySQL server is configured to listen on the correct network interface and port. By default, MySQL listens on port 3306. Check your `my.cnf` or `my.ini` configuration file for the `bind-address` and `port` directives. If `bind-address` is set to `127.0.0.1`, the server will only accept local connections.
# Example my.cnf snippet
[mysqld]
port = 3306
bind-address = 0.0.0.0 # To allow connections from any IP address
# or bind-address = your_server_ip
3
From the client machine, attempt to connect to the MySQL server using the `mysql` command-line client, explicitly specifying the host and port. This helps isolate whether the issue is with the client application or general network connectivity.
mysql -h your_mysql_host_or_ip -P 3306 -u your_username -p
4
If the server is not running or not accessible on the specified port, restart the MySQL service. After restarting, re-verify its status and network accessibility.
# On systems using systemd
systemctl restart mysql

# On older systems using SysVinit
service mysql restart

3. Review Firewall Rules and Network Security Groups medium

Confirm that firewalls on both the client and server, as well as any cloud network security groups, allow traffic on the MySQL port.

1
On the MySQL server machine, check its local firewall (e.g., `ufw` on Ubuntu, `firewalld` on CentOS/RHEL, Windows Firewall) to ensure that incoming connections on the MySQL port (default 3306) are permitted from the client's IP address or subnet.
# Example using ufw on Ubuntu:
sudo ufw allow from your_client_ip to any port 3306

# Example using firewalld on CentOS/RHEL:
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="your_client_ip" port protocol="tcp" port="3306" accept'
sudo firewall-cmd --reload
2
If your MySQL server is hosted in a cloud environment (AWS, Azure, GCP), check the associated Network Security Groups or firewall rules. Ensure that inbound rules allow traffic on the MySQL port from your client's IP address or range.
N/A (This is typically done through the cloud provider's web console or CLI)
3
On the client machine, ensure that its local firewall is not blocking outbound connections to the MySQL server's IP address and port. This is less common but can occur in highly restricted environments.
N/A (Firewall configuration varies by OS. Consult your OS's firewall documentation.)
🔗

Related Errors

5 related errors