php SQLSTATE[HY000] [1045] 用户“root”@“localhost”的访问被拒绝(使用密码:YES)symfony2

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30594962/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 21:54:26  来源:igfitidea点击:

SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) symfony2

phpmysqlsymfony

提问by Denis Rd

When I try to login I get an error:

当我尝试登录时出现错误:

SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)

SQLSTATE[HY000] [1045] 用户“root”@“localhost”的访问被拒绝(使用密码:YES)

parametrs.yml:

参数.yml:

This file is auto-generated during the composer install

这个文件是在 composer 安装过程中自动生成的

parameters:
    database_driver: pdo_mysql
    database_host: localhost
    database_port: null
    database_name: sgce
    database_user: root
    database_password: mikem
    mailer_transport: smtp
    mailer_host: 127.0.0.1
    mailer_user: null
    mailer_password: null
    locale: en
    secret: ThisTokenIsNotSoSecretChangeIt

My OS is Debian

我的操作系统是 Debian

Thanks for your help.

谢谢你的帮助。

[mysqld_safe]
socket      = /var/run/mysqld/mysqld.sock
nice        = 0

[mysqld]
#
# * Basic Settings
#
#skip-grant-tables
user        = mysql
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
port        = 3306
basedir     = /usr
datadir     = /var/lib/mysql
tmpdir      = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address       = 127.0.0.1
bind-address        = 10.1.4.3

回答by DerStoffel

This is due to your mysql configuration. According to this error you are trying to connect with the user 'root' to the database host 'localhost' on a database namend 'sgce' without being granted access rights.

这是由于您的 mysql 配置。根据此错误,您尝试在未授予访问权限的情况下,将用户“root”连接到名为“sgce”的数据库上的数据库主机“localhost”。

Presuming you did not configure your mysql instance. Log in as root user and to the folloing:

假设您没有配置 mysql 实例。以 root 用户身份登录并执行以下操作:

CREATE DATABASE sgce;

CREATE USER 'root'@'localhost' IDENTIFIED BY 'mikem';
GRANT ALL PRIVILEGES ON sgce. * TO 'root'@'localhost';
FLUSH PRIVILEGES;

Also add your database_port in the parameters.yml. By default mysql listens on 3306:

还要在 parameters.yml 中添加您的 database_port。默认情况下,mysql 监听 3306:

database_port: 3306

回答by danger89

database_password: passwordwould between quotes: " or '.

database_password: password将在引号之间:" 或 '。

like so:

像这样:

database_password: "password"

database_password: "password"

回答by Samuel Jr Fredrick

'default' => env('DB_CONNECTION', 'mysql'),

add this in your code

将此添加到您的代码中

回答by Mitan

I'm Using Xampp and Laravel 5.8 in Windows 10, and i've been like this before. When i got this problem, My XAMPP is no have Password Then I tried to delete some codes in config>database.php

我在 Windows 10 中使用 Xampp 和 Laravel 5.8,我以前也是这样。当我遇到这个问题时,我的 XAMPP 没有密码然后我试图删除一些代码 config>database.php

'password' => env('DB_PASSWORD', ''),

And in .env

而在 .env

DB_PASSWORD=SECRET

the Problem is solved

问题已经解决了