All posts

Blog

MySQL Basics for Website Owners: Databases, Tables and Users Explained

Illustrated cover for the Developers guide "MySQL Basics for Website Owners: Databases, Tables and Users Explained"

Your WordPress posts, your store's products, your customer accounts and even most of your site's settings aren't stored in ordinary files. They live in a database, and on most web hosting accounts that database is MySQL or its close cousin MariaDB.

You can run a website for years without touching the database directly. But sooner or later you'll install a script that asks for "database name, username and password," or you'll need to move a site, restore a backup or fix a broken setting. Knowing the basics turns those moments from stressful to routine.

What is a database?

A database is an organized store of information that software can search, add to and update quickly. Instead of one giant text file, data is kept in a structured way so a website can instantly answer questions like "show me the ten newest blog posts" or "find the customer with this email address."

MySQL is a relational database management system: the software that stores the data and answers those questions. MariaDB began as a fork of MySQL and is designed to be highly compatible with it, so for most website owners the two behave the same way. Many hosts use MariaDB while still labeling the tools "MySQL."

Key terms in plain English

Database

A container for all the data belonging to one application. Typically, each website or app gets its own database, such as myshop_wp.

Table

A database holds multiple tables, each for one type of information. A WordPress database includes tables for posts, comments, users and options, among others.

Rows and columns

A table looks a lot like a spreadsheet:

  • Columns define what kind of information is stored, such as id, title, date or email.
  • Rows are individual records, like one specific blog post or one customer.

Primary key

A column (often id) that uniquely identifies each row. No two rows share the same primary key, which lets other tables reference a row reliably.

Database user

A login that an application uses to connect to the database. A user is given privileges that control what it can do: read data, write data, create tables and so on.

How a website uses MySQL

Here's what happens on a typical WordPress page view:

  1. A visitor requests a blog post.
  2. WordPress (written in PHP) connects to MySQL using the database name, username and password in its configuration file, wp-config.php.
  3. It runs queries to fetch the post, the site title, menus, widgets and settings.
  4. MySQL returns the data.
  5. WordPress combines that data with your theme to produce the HTML page.

If any of those connection details are wrong, or the database server is unavailable, you get the infamous "Error establishing a database connection" message.

A gentle introduction to SQL

SQL (Structured Query Language) is how you talk to the database. You don't need to master it, but recognizing the four basic commands helps a lot.

Read data:

SELECT title, post_date FROM wp_posts WHERE post_status = 'publish' ORDER BY post_date DESC LIMIT 5;

This asks for the titles and dates of the five newest published posts.

Add data:

INSERT INTO subscribers (email, signup_date) VALUES ('jane@example.com', '2026-04-01');

Change data:

UPDATE wp_options SET option_value = 'https://example.com' WHERE option_name = 'siteurl';

Remove data:

DELETE FROM subscribers WHERE email = 'jane@example.com';

Be careful with UPDATE and DELETE

An UPDATE or DELETE without a WHERE clause affects every row in the table. Before running either, always take a backup, double-check the WHERE condition, and consider running a SELECT with the same condition first to see which rows would be affected.

Creating a MySQL database in your hosting control panel

Most installers, such as Softaculous, create the database for you automatically. If you're installing an app manually, the process in cPanel or DirectAdmin generally looks like this:

  1. Open the MySQL Databases tool (sometimes called "MySQL Management").
  2. Create a new database. Many hosts add your account username as a prefix, so shop becomes something like account_shop.
  3. Create a database user with a strong, unique password. A password generator is your friend here.
  4. Add the user to the database and grant the privileges the application needs. For most CMS installs, that means all privileges on that one database.
  5. Note the details: database name, username, password and host. On shared hosting, the host is usually localhost.
  6. Enter those details in your application's installer or configuration file.

Managing your database safely

Use one user per application

Give each site its own database and its own user. If one site is compromised, the attacker can't automatically reach your other databases.

Use strong passwords

Applications store the database password in a config file, so you rarely need to type it. That means there's no reason not to make it long and random.

Back up regularly

Your database holds your content, orders and users. Losing it can be far worse than losing theme files. Use your host's backup tools, a backup plugin, or export the database to a .sql file. Keep copies off the server too, and test restoring one occasionally.

Keep an eye on size

Databases grow over time with post revisions, spam comments, expired temporary data and logs. A bloated database can slow down queries. Our guide on how to optimize a WordPress database covers practical cleanup steps.

Limit remote access

By default, many hosts only allow connections from the server itself. Only enable remote MySQL access for specific IP addresses you trust, and turn it off when you no longer need it.

Exporting and importing a database

When you move a site to a new host or create a staging copy, you'll usually:

  1. Export the database to a .sql file using phpMyAdmin, a backup tool or the mysqldump command.
  2. Create a new, empty database and user on the destination.
  3. Import the .sql file into the new database.
  4. Update the application's config file with the new connection details.

Large databases may hit upload limits in browser-based tools. In that case, compressing the file, using your host's import tool or using the command line over SSH is usually the answer.

Common MySQL errors and what they mean

  • "Access denied for user": wrong username or password, or the user hasn't been added to the database.
  • "Unknown database": the database name is misspelled or the database doesn't exist yet.
  • "Table doesn't exist": an import didn't finish, or the table prefix in your config doesn't match the tables.
  • "Too many connections": the server has reached its connection limit, often from a traffic spike or inefficient code.

If you're on Host Whimsy and get stuck, our knowledge base has guides for the hosting control panel, or you can open a support ticket.

Wrapping up

MySQL is the organized storage behind most dynamic websites. A database holds tables, tables hold rows and columns, and applications connect using a dedicated database user. With a little SQL, a habit of regular backups and some care around updates and deletes, you'll be able to install apps, move sites and fix common problems with confidence.