Databases

How to Connect a MySQL Database to WordPress

Create a MySQL database and user, grant privileges, and put the details into wp-config.php to connect WordPress.

WordPress isn't installed with a database by default — either you create one during a manual install, or the one-click installer creates it for you. If you're doing it by hand, here's the full connection recipe.

Part One — create the database and user

  1. Log into cPanel.
  2. Open MySQL Databases.
  3. Create a database under Create New Database. Note its full name — cPanel prefixes it with your account, e.g. youruser_wp.
  4. Create a MySQL user under Add New User, with its own password. Don't reuse your cPanel password.
  5. In Add User to Database, select the user and database, and grant ALL PRIVILEGES. This step is the one most people skip.

Part Two — put the details in wp-config.php

WordPress reads four values from public_html/wp-config.php. Open that file in File Manager:

define('DB_NAME', 'youruser_wp');
define('DB_USER', 'youruser_wpuser');
define('DB_PASSWORD', 'the password you just set');
define('DB_HOST', 'localhost');

The names must match cPanel exactly, including the prefix — copy them from the MySQL Databases screen rather than retyping. On WebFulHost shared hosting, DB_HOST is localhost.

Part Three — bring the data in

If you're moving an existing site, import its old data into the fresh database: open phpMyAdmin, select the new database, choose Import, and upload your SQL file. Then the site will show its old content.

Tip: for a brand-new WordPress install, install WordPress first with the one-click installer — it creates and connects the database for you, and you can skip Parts One and Two entirely.

Still not connecting?

"Error establishing a database connection" points back to one of these values. Re-verify each in How to Fix the Database Connection Error.

Was this article helpful?

Your feedback helps us improve our guides.

Still need a hand?

Contact WebFulHost Support — our team is available 24/7.