keepcalculator

06 Numbers and Powers

MySQL Database Setup for WordPress

Card No. 06·67717 · Updated · Standard formula, shown below

This guide walks you through creating a MySQL database and user for a WordPress installation. You’ll need access to your hosting control panel (like cPanel) or a MySQL client such as phpMyAdmin, plus the MySQL root or admin credentials. By the end, you’ll have a dedicated database and user ready for WordPress to connect to.

What You’ll Need

  • Access to your hosting control panel (cPanel, Plesk, etc.) or a MySQL client (phpMyAdmin, MySQL Workbench, or command line).
  • MySQL administrator credentials (username and password).
  • A text editor to save the database name, username, and password you create.

Step-by-Step

  1. Log in to your hosting control panel. Open your browser, go to your hosting provider’s login page, and enter your credentials. If you’re using a local server like XAMPP or MAMP, open the control panel and start MySQL.
  2. Open the database management tool. In cPanel, look for the “MySQL Databases” icon under the “Databases” section. In phpMyAdmin, you can access it via a link in the control panel or by navigating to http://yourdomain.com/phpmyadmin (if installed). For command line, open a terminal and connect with mysql -u root -p.
  3. Create a new database. In cPanel’s MySQL Databases, type a name for your database in the “New Database” field and click “Create Database.” In phpMyAdmin, click “New” in the left sidebar, enter a database name, choose “utf8mb4_general_ci” as the collation (or utf8mb4_unicode_ci), and click “Create.” For command line, run: CREATE DATABASE wp_db CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
  4. Create a MySQL user. In cPanel, scroll to “MySQL Users,” enter a username and password, and click “Create User.” In phpMyAdmin, click the “User accounts” tab, then “Add user account,” fill in the username, host (usually “localhost”), and password, and click “Go.” For command line, run: CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'strong_password';
  5. Assign the user to the database with all privileges. In cPanel, under “Add User to Database,” select the user and database you just created, click “Add,” and check the “ALL PRIVILEGES” box (or the specific ones you need) and click “Make Changes.” In phpMyAdmin, go to the database you created, click the “Privileges” tab, click “Add user account,” or if the user exists, edit their privileges and check “ALL PRIVILEGES.” For command line, run: GRANT ALL PRIVILEGES ON wp_db.* TO 'wp_user'@'localhost'; then FLUSH PRIVILEGES;
  6. Note down the database name, username, and password. You’ll need these when running the WordPress installation script. Keep them in a secure place.
  7. Test the connection (optional but recommended). In phpMyAdmin, log out and log back in with the new user. You should see the new database. Or, from the command line, run: mysql -u wp_user -p and enter the password, then USE wp_db; to confirm access.
  8. Proceed with WordPress installation. When you run the WordPress setup, enter the database name, username, password, and host (usually “localhost”). WordPress will test the connection and continue with the installation.

Common Mistakes

  • Using the wrong host. Most hosts use “localhost” for the database host, but some managed hosts (like WP Engine) use a separate hostname. Check your hosting provider’s documentation.
  • Not using utf8mb4. WordPress recommends utf8mb4 to support all characters, including emojis. Using an older collation like utf8_general_ci can cause issues with special characters.
  • Forgetting to grant privileges. If you create a user but don’t grant them access to the database, WordPress will fail with a “Error establishing a database connection” message.
  • Using the same password for everything. Weak passwords can compromise your site. Use a strong, unique password for the database user.
  • Creating the database with a prefix that includes your cPanel username. In cPanel, the database name is often prefixed with your account name (e.g., user_wp_db). Make sure you use the full name when configuring WordPress.

Tips

  • Use a dedicated database per site. If you host multiple WordPress sites, give each its own database and user. This improves security and makes backups easier.
  • Choose a strong password. Use a mix of uppercase, lowercase, numbers, and special characters. Avoid dictionary words or personal information.
  • Limit user privileges if possible. For most WordPress sites, ALL PRIVILEGES is fine, but if you want to be more restrictive, you can grant only SELECT, INSERT, UPDATE, DELETE, and ALTER. However, some plugins may require more.
  • Back up your database regularly. Use a plugin or your hosting’s backup tools to keep copies of your database. This is crucial for recovery.
  • Keep your database credentials in wp-config.php. WordPress stores them in the wp-config.php file. Make sure that file is not publicly accessible (it usually isn’t, but verify).

Troubleshooting

  • “Error establishing a database connection” – This usually means the database name, user, password, or host is incorrect. Double-check the values in your wp-config.php file. Also, ensure the user has been granted privileges to the database.
  • “Access denied for user” – This indicates the username or password is wrong, or the user doesn’t have permission to connect from the host you’re using. Verify the username and password, and check the host (localhost vs. a remote host).
  • “Unknown database” – The database name is incorrect. Check that you created the database and that you’re using the exact name (including any prefix).
  • Connection timeout – This can happen if the MySQL server is down or if the host is unreachable. Check that MySQL is running on your server. If you’re using a remote database, ensure the hostname and port are correct.
  • Can’t log into phpMyAdmin – If you can’t access phpMyAdmin, your hosting may have it disabled or you may need to use a different URL. Contact your hosting provider for support.

Frequently Asked Questions

Can I use an existing database for WordPress?

Yes, you can use an existing database, but it’s safer to create a new one to avoid conflicts with other applications. If you do use an existing one, make sure the table prefix is unique (e.g., wp_ vs. myother_).

What is the default MySQL host for WordPress?

For most shared hosting, it’s localhost. For managed WordPress hosts or cloud databases, it may be a different hostname provided by your host. Check your hosting documentation.

Do I need to create a database before installing WordPress?

Yes, WordPress requires a database to store content, settings, and user data. The installation script will ask for database details, so you must have it ready.

Can I change the database name or user after installation?

Yes, you can, but it requires updating your wp-config.php file with the new details. You’ll also need to ensure the new user has privileges to the database. It’s easier to do this before installation.

What is utf8mb4 and why does WordPress recommend it?

utf8mb4 is a character set that supports the full Unicode standard, including emojis and special characters. Older sets like utf8 only support up to 3 bytes, missing some characters. WordPress uses utf8mb4 by default, so your database should match.

Is it safe to use the root user for WordPress?

It’s not recommended. Using the root user for a web application is a security risk. Create a dedicated user with limited privileges to reduce the impact of a compromise.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →