Access denied for user 'root'@'localhost' when accessing DKAN

458 views Asked by At

I installed DKAN and I briefly worked. Then I closed everything and tried to open it again, I got the following error message:

The website encountered an unexpected error. Please try again later.
Drupal\Core\Database\DatabaseAccessDeniedException: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) in Drupal\Core\Database\Driver\mysql\Connection::open() (line 156 of /var/www/html/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php).
Drupal\Core\Database\Driver\mysql\Connection::open(Array) (Line: 376)
Drupal\Core\Database\Database::openConnection('default', 'default') (Line: 166)
Drupal\Core\Database\Database::getConnection('default')
call_user_func_array('Drupal\Core\Database\Database::getConnection', Array) (Line: 79)
Drupal\Component\DependencyInjection\PhpArrayContainer->createService(Array, 'database') (Line: 171)
Drupal\Component\DependencyInjection\Container->get('database', 1) (Line: 260)
Drupal\Component\DependencyInjection\PhpArrayContainer->resolveServicesAndParameters(Array) (Line: 62)
Drupal\Component\DependencyInjection\PhpArrayContainer->createService(Array, 'cache.container') (Line: 171)
Drupal\Component\DependencyInjection\Container->get('cache.container') (Line: 513)
Drupal\Core\DrupalKernel->getCachedContainerDefinition() (Line: 868)
Drupal\Core\DrupalKernel->initializeContainer() (Line: 466)
Drupal\Core\DrupalKernel->boot() (Line: 656)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

I believe it could be the fact that I have entered as username the value admin but when I was creating it on my Laptop (I use Ubuntu 18) the database was created from root. However, I still don't know if that is really the problem or how could I fix it

1

There are 1 answers

0
danblack On BEST ANSWER

First create a new database user for your Drupal instance rather than using root.

By running mysql -u root -p on the command line, and entering the password. Then:

 CREATE USER drupal@localhost IDENTIFIED BY 'secretpassword';
 GRANT ALL ON drupaldatabase.* TO drupal@localhost;

Second, configure the Drupal application in its configuration file to use this new user.