Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
VGSources
Blog

How to Set Up a MySQL Database for a WordPress Installation (2026 Guide)

A practical 2026 walkthrough for creating a WordPress MySQL database, assigning a user, configuring wp-config.php, running the installer and troubleshooting failed connections.
Length10 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To install WordPress, you need a MySQL or MariaDB database, a dedicated database user, and the connection values in wp-config.php. Check the server requirements, create the database and user through your host or SQL, grant the appropriate permissions, configure WordPress, then open /wp-admin/install.php to finish the site setup.

What WordPress needs before you create a database

WordPress stores posts, pages, settings, users, comments, plugin data and other structured content in MySQL or MariaDB. The database is separate from the WordPress PHP files, so both parts must be available and able to communicate through the hosting account.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

WordPress’s “Before You Install” guidance, updated October 14, 2026, lists these minimum requirements:

  • PHP 7.4 or greater.
  • MySQL 5.7 or greater, or MariaDB 10.3 or greater.
  • HTTPS support for the site.

Ask your hosting provider for the database server name, database port, database host value, and whether it expects a Unix socket. Do not assume that localhost is correct: it is common on traditional shared hosting, but providers can require another hostname, a non-default port or a socket path.

Choose the database setup method

The result is the same regardless of the interface: one database, one WordPress database user, and a grant that lets that user work on the selected database. The practical difference is how much control you have.

Route Best for What you need to know
Hosting control panel Most shared-hosting installations Use the provider’s database wizard, often in cPanel, Plesk or DirectAdmin. The host may automatically create the user, grant access and add a required account-name prefix.
phpMyAdmin Administrators who prefer a browser interface Create the database, create a separate user, then assign that user to the database with the required privileges.
MySQL client VPS, dedicated servers and shell-based deployments Run SQL as an account allowed to create databases and users. You must supply the correct host value and manage grants yourself.
Provider-managed database Hosting plans that automate database provisioning Copy the provider’s database name, username, password and host exactly. Some services do not permit arbitrary database names or users.
WP-CLI Repeatable command-line deployments With a valid wp-config.php, wp db create issues the database-creation statement using its configured connection values.

A single WordPress site normally gets its own database. If your host limits the number of databases, several sites can share one database when each installation uses a distinct table prefix. Keep the prefix unique and record which prefix belongs to each site; otherwise, maintenance or a mistaken import can affect another installation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Plan the names, host and character settings

Database and user names

Choose names that identify the site without exposing unnecessary information. Use a different database user for each installation rather than reusing an administrator account across sites. Shared hosts frequently prepend the hosting-account username, so a database entered as blog may become something like account_blog. The final prefixed name is the value that belongs in DB_NAME.

Database host

DB_HOST is the address WordPress uses to reach MySQL. localhost is typical when PHP and MySQL run on the same server, but a managed or remote database may provide a DNS hostname. If the provider gives a port, include it in the host value in the format the provider documents. If it supplies a Unix socket, use that socket path instead of guessing.

Character set and collation

WordPress’s database-creation guidance recommends the utf8 series and suggests utf8mb4_general_ci when an appropriate language-specific collation is not available. Leave the DB_CHARSET and DB_COLLATE constants at their defaults unless you understand the consequences of changing them. A collation affects sorting and comparisons, so selecting one merely because its name looks familiar can produce unexpected results for multilingual content.

Create the database in a hosting control panel

The labels vary, but the workflow is consistent in cPanel, Plesk, DirectAdmin and similar panels.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Sign in to the hosting control panel and open the section named MySQL Databases, Databases or an equivalent database manager.
  2. Create a new database. Enter the short name supplied by your plan, then note the complete name including any automatic account prefix.
  3. Create a new MySQL user with a long, unique password. Do not reuse the hosting-login password.
  4. Use Add user to database, Assign user or the equivalent action to attach the new user to the WordPress database.
  5. When the panel offers privileges, select the option that grants the user access to that database. Record the exact database name, username, password and host shown by the panel.
  6. Check whether the panel reports a custom host or port. If it does, that value takes precedence over localhost.

Some hosts create the database and user together and hide the grant step. That is acceptable as long as the resulting user is attached to the intended database and the panel displays credentials that WordPress can use.

Create the database with the MySQL client

Use this route when you have shell access and an administrative MySQL account. Replace every placeholder with a value supplied by your provider or chosen for this site. The host in the user definition must match the host from which WordPress will connect.

CREATE DATABASE databasename;
CREATE USER "wordpressusername"@"hostname" IDENTIFIED BY "strong-password";
GRANT ALL PRIVILEGES ON databasename.* TO "wordpressusername"@"hostname";
FLUSH PRIVILEGES;

What each statement does

  • CREATE DATABASE makes the empty database that WordPress will populate.
  • CREATE USER creates a login restricted to the specified account name and connection host.
  • GRANT ALL PRIVILEGES ON databasename.* gives that user access to every table in this database, not to unrelated databases.
  • FLUSH PRIVILEGES reloads the privilege information after the grant.

Using "wordpressusername"@"localhost" when WordPress actually connects from another host creates a valid account that still cannot log in from the application server. Conversely, making the host broader than your provider requires can grant access from locations that do not need it. Use the exact host value documented for your environment.

Put the connection details in wp-config.php

WordPress’s base configuration file contains the database connection information and other site-wide settings. In the WordPress package, copy or rename wp-config-sample.php to wp-config.php, then edit the database section.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
define( 'DB_NAME', 'database_name_here' );
define( 'DB_USER', 'username_here' );
define( 'DB_PASSWORD', 'password_here' );
define( 'DB_HOST', 'localhost' );
Constant Value to enter Common mistake
DB_NAME The complete database name, including a hosting-account prefix if one exists Entering the unprefixed short name from the creation form
DB_USER The complete MySQL username Using the hosting-panel login rather than the database user
DB_PASSWORD The password assigned to that database user Leaving quotation marks out of the PHP string or copying an extra space
DB_HOST The provider’s hostname, localhost, a host-and-port value, or a Unix socket path Assuming every server uses localhost

Keep the existing DB_CHARSET and DB_COLLATE definitions unless you have a specific compatibility reason to alter them. Treat wp-config.php as a secret-bearing file: limit who can read it, avoid pasting it into public support forums, and remove credentials from shell history or temporary notes after use.

If several WordPress installations share one database, set a different $table_prefix for each installation in its own configuration file. A unique prefix prevents WordPress from treating another site’s tables as its own.

Upload WordPress and run the installer

  1. Upload the WordPress files to the domain’s document root or to the subdirectory where the site will live.
  2. Place the completed wp-config.php in the WordPress directory. Ensure the PHP process can read it.
  3. Open https://example.com/wp-admin/install.php. For a subdirectory installation, use that subdirectory in the URL.
  4. Enter the site title, administrator account and other installer fields, then submit the form.
  5. WordPress creates its tables in the selected database and redirects you to the administration area when setup succeeds.

If wp-config.php is absent, WordPress can display a form asking for the database details and attempt to create the file. The web server still needs permission to write the configuration file during that step. Creating the file yourself is usually easier to audit because you can verify every value before opening the installer.

Use least privilege after the initial setup

During a first installation, many guides grant the WordPress user all privileges on its own database because plugins and updates can need schema changes. That broad grant should not automatically become the permanent operating model.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

WordPress Developer Resources states: “For normal WordPress operations, such as posting blog posts, uploading media files, posting comments, creating new WordPress users and installing WordPress plugins, the MySQL database user only needs data read and data write privileges to the MySQL database; SELECT, INSERT, UPDATE and DELETE.”

Normal operation

For day-to-day requests, the account needs the ability to select, insert, update and delete rows in the WordPress database. Those permissions cover publishing, media metadata, comments and user records without allowing routine requests to alter the database structure.

Schema-changing work

Some plugins, migrations and major updates need temporary schema privileges such as ALTER or permission to create tables. WordPress hardening guidance recommends granting those rights only for the operation that needs them, then removing them afterward. Coordinate the change with your host if the control panel does not let you edit individual grants.

Practical privilege workflow

  1. Complete the installation with the permissions your provider requires.
  2. Confirm that the site can publish a post, upload media and manage users.
  3. Reduce the database user to normal read/write data privileges when your environment allows it.
  4. Before a schema-changing plugin or update, create a backup and temporarily elevate the account only as needed.
  5. Run the update, test the site, then restore the restricted grant.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Command-line creation with WP-CLI

WP-CLI can create the database after the connection values are present in wp-config.php. From the WordPress directory, run:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
$ wp db create
Success: Database created.

The wp db create command issues a CREATE DATABASE statement using DB_HOST, DB_NAME, DB_USER and DB_PASSWORD loaded from wp-config.php. The database user therefore needs permission to create the database, and the host must allow that account to connect. If your provider already created the database, do not run this command merely to test the credentials; proceed to the installer instead.

Diagnose “Error establishing a database connection”

Work through the values and permissions in a fixed order rather than repeatedly changing several settings at once.

Symptom or situation Check Correction
WordPress rejects the connection immediately Compare DB_NAME, DB_USER, DB_PASSWORD and DB_HOST character by character with the provider’s values. Correct the mismatched constant, including prefixes, capitalization and accidental spaces.
Credentials look right but access is denied Confirm that the WordPress user is assigned to the selected database and that its MySQL account host matches the application server. Attach the user to the database or recreate the grant with the provider-supplied host.
The database server cannot be reached Ask whether the MySQL service is running and whether the provider uses a remote hostname, custom port or socket. Use the documented host, port or socket in DB_HOST; restart or escalate the database service when you administer the server.
The panel created a name different from the one you entered Look for the hosting-account prefix in the panel’s final database and username listings. Copy the complete names into DB_NAME and DB_USER.
The installer opens but cannot create tables Check whether the account has write access to the database and whether the database uses the intended character settings. Repair the grant, then retry the installer after confirming the database is reachable.
A plugin or update fails while ordinary posts work Determine whether the operation requires a schema change. Temporarily grant the required schema privilege, perform the update, test it and remove the elevation.

Verify the server-side facts

  • Confirm that the MySQL or MariaDB version meets WordPress’s stated minimum.
  • Confirm that PHP can reach the database host through the account’s network policy.
  • Check that the database exists on the same server named in DB_HOST; a database created on one server is not automatically visible on another.
  • Make sure the password in wp-config.php is the current password, especially after changing it in a control panel.

If the values and grant are correct but the service is unavailable, the problem is on the database server or hosting network rather than in WordPress’s installer. Your provider can confirm service status, connection limits and the correct endpoint.

Pre-install and post-install checklist

Before opening the installer

  • PHP is 7.4 or newer.
  • MySQL is 5.7 or newer, or MariaDB is 10.3 or newer.
  • HTTPS is available for the site.
  • The database exists and its complete name is recorded.
  • A dedicated database user has a unique password and access to that database.
  • The provider’s host, port or socket value is recorded.
  • wp-config.php contains the four matching connection constants.

After WordPress loads

  • Open the dashboard and publish a test post.
  • Upload a test image and verify that the media library records it.
  • Create or edit a non-administrator test user if your workflow requires user management.
  • Confirm that the site uses HTTPS and that the administration URL resolves correctly.
  • Record the database name, user, host and table prefix in your deployment documentation without storing the password in plain text.
  • Apply the least-privilege grant that your plugins and update process support.

Which setup route should you use?

Use the hosting panel when you are on shared hosting or when the provider automatically handles prefixes, grants and service endpoints. Choose SQL when you administer the server and need repeatable, auditable commands. Use WP-CLI when the site is deployed from scripts and the database account is already authorized to create databases. A provider-managed database is appropriate when the host supplies the endpoint and credentials as part of the service, but you must still copy those values exactly into WordPress.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The safest general pattern is a dedicated database per site, a dedicated user, a host value confirmed by the provider, and normal operation restricted to data read/write privileges. Shared databases and temporary privilege elevation are workable alternatives when hosting limits or update requirements make them necessary, provided each site has a unique table prefix and elevated access is removed after schema work.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.