Web Design & Development

Can WordPress Connect to a Database?

WordPress can connect to a database, and it can’t function without one. Every post, page, comment, user account and setting on a WordPress site lives in a database, and the files on your server are really just the machinery that reads from it and presents the result.

Most people never need to think about this until a site displays “Error establishing a database connection”, and everything disappears. Understanding what the connection is, and what can go wrong with it, turns a frightening message into a problem with a short list of likely causes.

What the Database Actually Does

WordPress separates a site into two parts. The files, meaning the WordPress software, your theme, your plugins and your uploaded media, sit in folders on the server. Almost everything else, the actual content and configuration, sits in the database.

  • Posts, pages and custom content types, including their text and metadata
  • Comments, along with user accounts, roles and hashed passwords
  • Site settings, menus, widgets and many theme and plugin options
  • Plugin data, such as form entries, order details or SEO settings, depending on the plugin

When a visitor requests a page, WordPress runs code that queries the database, assembles the result into HTML, and sends it to the browser. This happens on every uncached request, which is one reason a slow database can slow an entire site.

How WordPress Connects

The connection details live in a file called wp-config.php in the root of your WordPress installation. It tells WordPress where the database is and how to log in.

define( ‘DB_NAME’, ‘your_database_name’ );define( ‘DB_USER’, ‘your_database_user’ );define( ‘DB_PASSWORD’, ‘your_database_password’ );define( ‘DB_HOST’, ‘localhost’ );

The four values are the database name, a database username, that user’s password, and the host where the database server lives. On most shared hosting the host is localhost, meaning the database runs on the same server as the site. Some hosts use a separate database server with its own address.

WordPress natively works with MySQL and MariaDB, closely related database systems that most hosting providers supply by default. An official SQLite integration plugin also exists, and WordPress Playground uses it, though MySQL or MariaDB remains the normal choice for live sites.

What Goes Wrong, and Why

The classic error, “Error establishing a database connection”, means WordPress could not connect, or could not use the database once connected. The causes usually fall into a short list.

  • Incorrect credentials in wp-config.php, often after a site migration, a hosting change or a password reset
  • The database server being down or overloaded, which may be a hosting problem rather than anything you have done
  • A corrupted database, or one that has run out of allocated space
  • The wrong database host, which is common when moving between hosts that use different server addresses
  • A hacked or damaged wp-config.php file

If you run a small business site in Witney or anywhere across Oxfordshire, the sensible first move is the same wherever you are. Check with your host whether their database server is running normally before touching anything, since that single question rules out a surprising number of cases.

A Sensible Way to Troubleshoot

  • Take a backup of your files and database first, if you can still reach them, before changing anything
  • Check your hosting control panel or status page for server or database problems
  • Confirm the four values in wp-config.php match the database details shown in your hosting control panel
  • Try logging into the database through your host’s database tool to test that the username and password actually work
  • Ask your host to check the database server and, if needed, repair or restore from a backup

Can WordPress Use a Different or Remote Database?

Yes, within limits. Pointing DB_HOST at a remote database server is supported and is common on larger hosting setups, though it adds network delay and needs careful security. Connecting to a second, separate database for extra data is possible through WordPress’s database class, wpdb, using custom code or a suitable plugin.

Replacing the core database entirely with something other than MySQL, MariaDB or the SQLite integration is not standard, and tends to need specialist development. For most sites, the sensible approach is to stay with the default and make sure it is well maintained.

Looking After Your Database

  • Keep regular, automatic backups of both files and database, and test that you can restore them
  • Use a strong, unique database password, and never reuse it elsewhere
  • Protect wp-config.php, since it holds your credentials and should never be publicly readable
  • Clear out old revisions, spam comments and expired transients periodically, as database bloat can slow a site
  • Choose hosting with a reliable database server, since cheap, overcrowded hosting is a common cause of slow queries and outages

A Quick WordPress Database Checklist

☐  Know where your wp-config.php file is and keep a secure copy of its values

☐  Confirm automatic backups include the database, not just the files

☐  Test restoring a backup at least once, ideally on a staging copy

☐  Use a strong, unique database password and restrict access to wp-config.php

☐  Check your host’s status page first when a database error appears

☐  Review database size and clean out unnecessary data a few times a year

Frequently Asked Questions

Can WordPress work without a database?

Not in its standard form. WordPress stores its content and settings in a database, so it needs one to run. Static site tools can generate plain files without a database, but that is a different way of building a site.

What database does WordPress use?

MySQL or MariaDB in nearly all cases. Most hosts provide one of the two automatically when you set up a WordPress site.

How do I find my WordPress database name and username?

They are stored in your wp-config.php file, which you can view through your host’s file manager or an FTP connection. Your hosting control panel also lists the databases and users that exist on your account.

Is it safe to edit the database directly?

You can do it through tools like phpMyAdmin, but it is easy to cause damage. Always take a full backup first, and only make changes if you understand exactly what they do. For most tasks, the WordPress dashboard or a reputable plugin is a safer route.

Will moving host break my database connection?

It often needs the connection details updated, since the database name, username, password and host will probably differ at the new host. Updating wp-config.php with the new values is typically the fix, and a good migration process handles this for you.

Facing a Database Error You Cannot Resolve?

If you would like a second opinion on a database problem, or want to check your backups are set up properly, get in touch for a plain conversation with no obligation and no sales pitch.

Keep reading

Further reading

What Is the HTML Document Structure?

Every web page you have ever visited, however simple or elaborate it looks, is built on the same basic skeleton. This is the first in a short series on the building blocks of HTML, starting at the foundation, because understanding this structure makes almost everything else about how websites work easier to grasp. You do […]

21 August 2026 · 5 min read

Why Use Semantic HTML?

There is a version of this question that sounds technical and dry. There is another version that is actually a business question: why does it matter how my website’s code is structured if it looks the same in the browser either way? The answer covers four distinct areas, and none of them is trivial. Search […]

29 July 2026 · 9 min read