Fixing the 'Cannot Select Database' Error During WordPress Installation
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.phpfile 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.phphas 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
user123and you created a database namedwordpress, the full name might beuser123_wordpress. - Check your hosting control panel to find the database's true, full name and update
DB_NAMEinwp-config.phpaccordingly.
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
- Database name in
wp-config.phpis spelled correctly. - The database user has been granted ALL PRIVILEGES on the database.
- The database has been created and exists on the server.
- Any required database name prefix from the host has been added to the
DB_NAMEvalue. - The
DB_HOSTvalue 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.
Related Support Threads Support
-
Yet another “Cannot select database” problemhttps://wordpress.org/support/topic/yet-another-cannot-select-database-problem/
-
Installing WordPress to raspberry PIhttps://wordpress.org/support/topic/installing-wordpress-to-raspberry-pi/
-
Can’t select databasehttps://wordpress.org/support/topic/cant-select-database-64/
-
what is wrong with mysql?https://wordpress.org/support/topic/what-is-wrong-with-mysql/
-
Can’t select databasehttps://wordpress.org/support/topic/cant-select-database-54/
-
Can’t select databasehttps://wordpress.org/support/topic/cant-select-database-53/
-
We were able to connect to the database server (which means your username and pahttps://wordpress.org/support/topic/we-were-able-to-connect-to-the-database-server-which-means-your-username-and-pa-2/
-
Can’t select databasehttps://wordpress.org/support/topic/cant-select-database-63/
-
Can’t select databasehttps://wordpress.org/support/topic/cant-select-database-62/
-
not install wordpress, eror: not find databaseshttps://wordpress.org/support/topic/not-install-wordpress-eror-not-find-databases/
-
이거 왜 그런건가요??https://wordpress.org/support/topic/%ec%9d%b4%ea%b1%b0-%ec%99%9c-%ea%b7%b8%eb%9f%b0%ea%b1%b4%ea%b0%80%ec%9a%94/