"Error establishing database connection" in subdirectory

I am following this tutorial for three WordPress sites:

The first two were set up with no issues. The third, however, is in a subdirectory. I tested that there is a connection with mysql -u <DB_USER> -p<DB_PASSWORD> -h <DB_HOST> <DB_NAME> I also tested that it is reading my wp-config.php by adding die(“Loading this file now”); to the top. So it does display that line now. I also looked at How To Debug the WordPress “Error Establishing Database Connection” but none of those suggestions helped.

I am thinking it is perhaps related to the fact that I putting WordPress in a subdirectory: Maybe some permission issue?

Any ideas?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello, @leorawe

Normally the best thing to do is to keep the currently installed. Would you mind listing all the available options that you get?

Regards, Alex

Hello, @leorawe

First, you can ensure that the MySQL service is up and running:

  1. sudo systemctl status MySQL

You can double-check the database credentials in the wp-config.php file and make sure that they are added correctly in the file, e.g no blank spaces or typos.

It’s worth attempting to connect to the database from the command line, just to make sure. Copy and paste the details right from the config file into the following command:

  1. mysqlshow -u database_username -p

You’ll be prompted for a password. Paste it in and press ENTER. If you get an Access denied error, your username or password is incorrect.

You can also double-check the site files/folders permissions and ownerships. to set the correct permissions on the WordPress directories and files:

sudo find /var/www/wordpress/ -type d -exec chmod 750 {} \;
sudo find /var/www/wordpress/ -type f -exec chmod 640 {} \;

Another thing to check is the salt and key values in the wp-config.php file. More information can be found in our tutorial here:

Hope that this helps! Regards, Alex

Hi @leorawe,

It’s possible there is a permissions issue. You need to make your Folders 755 and your Files 644 permissions.

Additionally, what I think it’s mostly possible is your Password being wrong, at least what you’ve typed in your wp.config.php. Another common thing that occurs is the password containing the single quote symbol - ’ which is not being interpreted as part of the password.