FAQ Databases & MySQL

Why is my database host "localhost"?

It means "this same machine" — not a placeholder, and not something to change unless you actually need to.

Updated 4 min read Beginner

"localhost" means "this same server" — it is an instruction to connect to the database running right here, on the same machine as the website itself, rather than to a database anywhere else. On shared and most standard hosting, the website's files and its MySQL database live on the same server, so localhost is correct and is what nearly every WordPress install and PHP application expects by default.

Why it looks strange the first time you see it

It reads like a placeholder value someone forgot to fill in, especially next to a real-looking database name and username. It is not a placeholder — it is a genuine hostname, just one with a special meaning: "connect to whatever is on this machine" rather than naming a specific server by address. Every computer, not just a web server, understands localhost the same way.

When it is not the right value

A small number of setups genuinely need something other than localhost:

  • A separate database server. Some larger hosting setups, and most VPS or dedicated arrangements where you have deliberately split an application server from a database server, put the database on different hardware entirely. In that case the host is a specific hostname or IP address your host provides, and using localhost would try to connect to a database that is not actually there.
  • Mid-migration. While moving a site between servers, an application briefly needs to point at whichever server currently holds the live database, which is not always the one the application itself is running on yet.
  • A remote application. A script or app running somewhere else entirely — your own computer, a different hosting account — connecting into this database needs the server's real address, since localhost from that other machine would simply mean itself, not your server.

If you are not sure which situation applies to you, check the databases section of your control panel — it will state the correct host value for your account if it is anything other than localhost.

What happens if you get it wrong

Entering the wrong host value produces the same generic symptom as almost every other database misconfiguration: a connection failure, often reported simply as an inability to reach the database at all rather than anything specifically about the host being wrong. If your credentials all look correct and the connection still fails, the host value is one of the things worth checking — see fixing a database connection error for the full list of causes in the order worth checking them.

For the full set of values a connection needs and working code examples, see connecting an application to MySQL.

Related reading