Menu

MySQL Error 1042: Can't Get Hostname for Your Address

Troubleshoot MySQL Error 1042 by checking reverse DNS from the server, host_cache resolution counters, and client host matching.

Posted on By Updated on
On this page

MySQL Error 1042 (08S01, ER_BAD_HOST_ERROR) means the server returned Can't get hostname for your address. Unlike Error 2005, where the client cannot resolve the server’s hostname, Error 1042 points to hostname lookup for the client address from the server side. See the MySQL 8.4 error reference.

For a TCP client, start by asking the database administrator to check name resolution from the MySQL server for the client IP, including whether a resolved host name maps back to that same IP. MySQL documents its host cache as performing IP-to-host and host-to-IP validation; its Performance Schema table exposes the cached lookup results and DNS error counters. See DNS lookups and the host cache.

Inspect the client address in the host cache

The host_cache table is exposed through Performance Schema and tracks non-localhost TCP clients. From an administrative connection to the same server, first check the relevant settings:

SHOW GLOBAL VARIABLES
WHERE Variable_name IN ('performance_schema', 'host_cache_size', 'skip_name_resolve');

If performance_schema is OFF, the table cannot provide diagnostics. A host_cache_size of 0 disables the cache, so cached DNS counters are unavailable even though the server still performs DNS lookups for connections. If skip_name_resolve is enabled, the server avoids DNS lookups and matches accounts by IP address; do not toggle it as a quick fix because name-based user@host accounts may stop matching. See DNS lookups and the host cache and Performance Schema system variables.

If those settings allow host-cache diagnostics, look up the IP address shown in the connection logs or network configuration:

SELECT
  IP,
  HOST,
  HOST_VALIDATED,
  COUNT_NAMEINFO_TRANSIENT_ERRORS,
  COUNT_NAMEINFO_PERMANENT_ERRORS,
  COUNT_ADDRINFO_TRANSIENT_ERRORS,
  COUNT_ADDRINFO_PERMANENT_ERRORS,
  FIRST_SEEN,
  LAST_SEEN
FROM performance_schema.host_cache
WHERE IP = '203.0.113.25';

Replace the example address with the client IP as seen by the server. HOST_VALIDATED = NO means MySQL is still attempting resolution; the counters distinguish transient and permanent lookup failures. The host_cache table reference lists each column. If the row is absent, confirm that the connection uses a non-local TCP address and that the host cache is enabled. If the table itself is unavailable, check whether Performance Schema is enabled and follow the server logs or provider DNS diagnostics instead.

Check DNS and name-based account matching on the server

Ask the database or network administrator to verify reverse DNS for the client IP from the database server’s network, then confirm the returned host name resolves back to the original IP. Check for temporary resolver outages, missing PTR records, or inconsistent forward and reverse DNS. A lookup that works from a developer workstation does not prove that the database server can resolve the client address.

Also ask whether skip_name_resolve is enabled. When it is enabled, MySQL uses IP addresses rather than host names when matching client hosts to account rows; accounts that depend on DNS host names may no longer match. Changing this server-startup setting can affect multiple accounts, so review existing user@host entries and plan the change with the administrator. See MySQL’s skip_name_resolve system variable.

  • Error 1042: MySQL reports it could not get the hostname for the client address.
  • Error 2005: the client could not resolve the MySQL server hostname; see Error 2005 troubleshooting.
  • Error 2003: the client could not connect to the configured server and port; see Error 2003 troubleshooting.
  • Error 1130: the server says the client host is not allowed by its account host rules; see Error 1130 troubleshooting.

For other connection and authentication codes, use the MySQL connection error triage helper or browse MySQL Error Troubleshooting.