Menu

MySQL Error 2005: Unknown MySQL Server Host

Fix MySQL Error 2005 by checking the hostname, DNS from the client environment, and MySQL connection options or application settings.

Posted on By
On this page

MySQL client Error 2005 (HY000, CR_UNKNOWN_HOST) means the client could not resolve the MySQL server hostname. A typical message is Unknown MySQL server host 'db.example.com'. Client errors use HY000 as a general SQLSTATE, so use the error number and message to distinguish them. See the MySQL 8.4 client error reference.

Error 2005 occurs before a TCP connection reaches MySQL. Start with the hostname in the error message and test name resolution from the same machine, container, or runtime environment as the application.

Check whether the hostname resolves from the client

Verify the hostname spelling and ask the database administrator or hosting provider for the correct endpoint. Then query DNS from the client environment:

nslookup db.example.com

On Linux, getent ahosts db.example.com can also show the addresses returned through the system’s configured name service. A name that resolves on a developer’s laptop may not resolve inside a container, virtual machine, or private cloud network. Use a database service name only from a network where that name is defined, and use the approved private DNS name or address for the application environment.

Do not replace an unresolved private database name with an unverified public IP. Confirm the intended endpoint and network with the database administrator.

Check the MySQL client or application configuration

Make a direct client connection using the intended hostname:

mysql --protocol=TCP \
  --host=db.example.com \
  --port=3306 \
  --user=app_user \
  --password

The client prompts for the password. MySQL’s --host option accepts a host name or IP address. For the command-line client, MYSQL_HOST can provide a default hostname; option files and command-line arguments can also supply connection settings. See MySQL’s environment variable reference, then check the actual environment variables, option file, connection URL, or driver configuration used by the failing application. A correct DNS lookup does not help if the application is still using a different or misspelled host.

Error 2005 versus other connection errors

For other connection, authentication, and SQL problems, browse the MySQL error troubleshooting index.