Error 2005: Unknown MySQL server host, including 'localhost'
ERROR 2005 (HY000): Unknown MySQL server host 'localhost' (11001)Short answer
Error 2005 comes from the client: the name given as host could not be resolved. The value often comes from an option file or application setting, not from what you typed. Run the client with --no-defaults and an explicit address such as 127.0.0.1, then correct the stored host.
Fix it fast
1Find out which cause you have
Connect to the server by IP address and ignore option files, so no stored host value can interfere. If this works, the name was the problem.
mysql --no-defaults --host=127.0.0.1 --protocol=TCP -u root -p2Match what you see, then jump to its fix
What does the error look like?
ERROR 2005 (HY000): Unknown MySQL server host 'localhost' (11001)ERROR 2005 (HY000): Unknown MySQL server host 'no-such-host' (0)
Cause 1 of 2
The host name cannot be resolved by the client
1Check
The manual's example for this error is a connection to a host name that does not exist.
mysql --no-defaults --host=127.0.0.1 -u root -p -e "SELECT 1"2Fix
Use the server's IP address; for the local machine the manual recommends 127.0.0.1 instead of localhost to get a TCP/IP connection. Correct the name in your DNS or hosts entry separately.
mysql --host=127.0.0.1 --port=3306 -u root -p3Verify
The prompt opens and the server answers.
SELECT @@hostname, @@port;Confirmed by dev.mysql.com
Cause 2 of 2
A stored host value in an option file or app config is wrong
1Check
Programs read the [client] group of option files. A host= line there is used by every client, and command-line options are processed after the files, so --host overrides it. --no-defaults skips the files.
grep -R -n -E "^\s*host\s*=" ~/.my.cnf /etc/my.cnf /etc/mysql/ 2>/dev/null2Fix
Correct or remove the host line in the option file or the application's database settings, or pass --host on the command line.
[client]
host=127.0.0.13Verify
Start the client without any host option; it connects.
mysql -u root -p -e "SELECT 1"Confirmed by dev.mysql.com
How do I stop it coming back?
- Use 127.0.0.1 for local TCP connections in application settings.
- Keep one source of truth for the database host, and do not leave old values in option files.
- Test a new hostname with the mysql client before you put it in the app.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
Databases
Installing the Airflow MySQL provider fails on pkg-config or mysqlclient
Building the mysqlclient wheel fails during the install
The Airflow MySQL provider depends on mysqlclient, which pip compiles against the MySQL C client library.
2 causes, each with a fixDatabases
A query on Aurora MySQL dies with 'table /rdsdbdata/tmp/#sql... is full'
ERROR 1114 (HY000): The table '/rdsdbdata/tmp/#sqlfd_1586_2' is full
In Aurora MySQL 3, internal temporary tables share one pool, and when that pool and the memory-mapped overflow file are used up, a reader instance ends the query with error 1114.
3 causes, each with a fixDatabases
Azure Database for MySQL refuses a connection that does not use SSL
ERROR 3159 (HY000): Connections using insecure transport are prohibited while --require_secure_transport=ON.
Azure Database for MySQL Flexible Server requires encrypted connections by default (require_secure_transport = ON, TLS 1.2).
4 causes, each with a fixDatabases
Compiling a C or C++ program that includes mysql.h fails
undefined reference to `mysql_init'
The compiler only finds mysql.h when the MySQL client development files are installed and their folder is on the include path.
3 causes, each with a fixDatabases
DBeaver fails to resolve Maven dependencies when downloading a database driver
A driver library does not download automatically
DBeaver downloads driver jars from a Maven repository.
3 causes, each with a fixDatabases
DBeaver cannot verify the MySQL server certificate
unable to find valid certification path to requested target
DBeaver's MySQL driver is checking the server certificate and Java does not trust the CA that signed it.
2 causes, each with a fix