Back to Community

Fixing the 'Cannot Select Database' Error During WordPress Installation

11 threads Sep 7, 2025 CoreInstalling wordpress

Content

The "Cannot select database" error is a common, yet frustrating, hurdle many users face when installing WordPress. The error message clearly states that the connection to the database server is successful, but WordPress is unable to select the specific database it needs. This guide will walk you through the most common causes and their solutions, based on community experiences.

Why This Error Happens

This error occurs when the credentials in your wp-config.php file allow for a connection to the MySQL or MariaDB server, but something prevents the use of the specified database. The issue is almost always a mismatch between the configuration file and the actual database setup.

Common Solutions to the "Cannot Select Database" Error

1. Verify the Database Name in wp-config.php

This is the most frequent fix. The database name defined in your wp-config.php file must exactly match the name of the database you created, including case sensitivity.

  • Locate your wp-config.php file in the root WordPress directory.
  • Find the line: define( 'DB_NAME', 'database_name_here' );
  • Ensure the name inside the quotes is correct. Even a single typo will cause this error.

2. Check User Permissions for the Database

Creating a database and a user is not enough. The user must be explicitly granted all privileges to that specific database.

  • Access your database management tool (e.g., phpMyAdmin, Adminer, or a command line).
  • Verify that the user specified in wp-config.php has full permissions (SELECT, INSERT, UPDATE, DELETE, CREATE, etc.) on the target database.
  • Avoid using the 'root' user for security reasons. Create a dedicated user for your WordPress database.

3. Confirm the Database Actually Exists

It may seem obvious, but sometimes the database listed in the configuration file was never created, or was created under a slightly different name. Double-check your database management interface to confirm the database is present.

4. Look for a Database Prefix from Your Host

Many shared hosting providers automatically add a prefix to your database name, usually your username or cPanel account name.

  • For example, if your cPanel username is user123 and you created a database named wordpress, the full name might be user123_wordpress.
  • Check your hosting control panel to find the database's true, full name and update DB_NAME in wp-config.php accordingly.

5. Specify the Correct Database Host and Port

While localhost works for most local installations like XAMPP, some setups use a different hostname or port.

  • If your database server runs on a non-standard port (e.g., 3307 instead of 3306), you must specify it in the host field: define( 'DB_HOST', 'localhost:3307' );
  • On some network configurations or specific hosts, the database host might be a different address (like a remote server IP). Confirm the correct host with your hosting provider.

Summary Checklist

  1. Database name in wp-config.php is spelled correctly.
  2. The database user has been granted ALL PRIVILEGES on the database.
  3. The database has been created and exists on the server.
  4. Any required database name prefix from the host has been added to the DB_NAME value.
  5. The DB_HOST value is correct, including a port number if necessary.

By methodically working through these steps, you can almost always resolve the "Cannot select database" error and complete your WordPress installation successfully.