While login to WordPress, if you received can’t select database error, this article might help you. This error happens when WordPress is not able to select the correct database for your WordPress installation. It may occur when the database for your WordPress installation is modified, renamed etc.
Under this condition, you will see following message on the screen:
Can’t select database
We were able to connect to the database server (which means you are username and password is okay) but not able to select the <DATABASE_NAME> database.
You can try either of the fixes mentioned below and see if that helps you to resolve the problem.
Solved: Can’t select database error in WordPress
FIX 1 – Check the WP-Config file
Since this issue is related to database and WordPress configuration, it is recommended that you check the wp-login.php
file. This file has all the configuration details for your WordPress installation.
To locate this file, you need to login to your hosting account. Then go to File Manager. Inside File Manager, go to the directory where are WordPress is installed. In that directory, you’ll find wp-login.php
file. Select it and click Edit. The file will now open in text editor, where you can make changes and finally save them.
Make sure these values are correct:
define('DB_NAME', 'database_name'); define('DB_USER', 'database_username'); define('DB_PASSWORD', 'database_password'); define('DB_HOST', 'localhost');
If you’re running WordPress on a local server environment, you can fix the problem by replacing localhost with the IP. For example, on MAMP, the DB_HOST value when changed to the IP may seem to work.
define('DB_HOST', '127.0.0.1:8823');
FIX 2 – ALLOW AUTOMATIC REPAIR WORDPRESS
If WordPress is not able to correctly connect with your database, the chances may be that your database is corrupted. Under this condition you can configure WordPress to allow repairing the database.
For that, you have to again edit the wp-config.php
file. Simply add following line in the wp-config.php
file and Save it.
define('WP_ALLOW_REPAIR', true);
Kindly note that the user or administrator does not need to be logged in to access the repair functionality, when it is defined. This is because its main intent is to repair a corrupted database, and in some cases, you may even not able to login, when the database is corrupted.
Now retry accessing wp-admin
area of your WordPress installation and you’ll see this screen:
In above screen, you can click on Repair Database button start repairing your WordPress database.
If that doesn’t help, you can try Repair and Optimize Database button and that should finally fix the problem.
Hope this helps!