Drush not connecting to your database

Druapl 8 | Wamp 3 32 - bit | PHP 7

So you forget your Drupal admin password and is trying to run the command

drush upwd --password="givememypasswordback" "admin"

but it’s giving you something like

Follow the fix below:

Open the file :

‪sites\default\settings.php

Find the array :
$databases['default']['default'] = array (
'database' => 'dr8',
'username' => 'root',
'password' => '',
'prefix' => '',
'host' => '127.0.0.1',
'port' => '3306',
'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
'driver' => 'mysql',
);

Change 'host' => 'localhost, to 'host' => '127.0.0.1'

Save the changes.

Rerun the command.

Still not fixed? Getting the same error.

Add your MySql path (if not added yet) to Environment Variables (follow the steps below)

Go to windows search and search for “environment” and click on “Edit the system environment variables”.

Within the System Properties window click on “Environment Variables”.

Within the Environment Variables window under “System variables” find the variable “Path”, edit Path and add your_base_path\mysql5.7.14\bin to it and save all the changes.

Go back to bash (restart the bash) and run the command drush status and if everything is ok , you will get something like this:

d2

A Beginner’s Guide To Drush: The Drupal Shell is a good reference for beginners (and i’m not paid for this 🙂 )