访问 DKAN 时,用户 'root'@'localhost' 的访问被拒绝
Access denied for user 'root'@'localhost' when accessing DKAN
我安装了 DKAN 并进行了短暂的工作。然后我关闭所有内容并尝试再次打开它,我收到以下错误消息:
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)
我相信这可能是因为我输入了 username
值 admin
但是当我在我的笔记本电脑上创建它时(我使用 Ubuntu 18)数据库从 root
创建。但是,我仍然不知道这是否真的是问题所在,或者我该如何解决它
首先为您的 Drupal 实例创建一个新的数据库用户,而不是使用 root
。
在命令行输入运行 mysql -u root -p
,并输入密码。那么:
CREATE USER drupal@localhost IDENTIFIED BY 'secretpassword';
GRANT ALL ON drupaldatabase.* TO drupal@localhost;
其次,在 configuration file 中配置 Drupal 应用程序以使用这个新用户。
我安装了 DKAN 并进行了短暂的工作。然后我关闭所有内容并尝试再次打开它,我收到以下错误消息:
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)
我相信这可能是因为我输入了 username
值 admin
但是当我在我的笔记本电脑上创建它时(我使用 Ubuntu 18)数据库从 root
创建。但是,我仍然不知道这是否真的是问题所在,或者我该如何解决它
首先为您的 Drupal 实例创建一个新的数据库用户,而不是使用 root
。
在命令行输入运行 mysql -u root -p
,并输入密码。那么:
CREATE USER drupal@localhost IDENTIFIED BY 'secretpassword';
GRANT ALL ON drupaldatabase.* TO drupal@localhost;
其次,在 configuration file 中配置 Drupal 应用程序以使用这个新用户。