Symfony - doctrine:SQLSTATE [HY000] [1045]访问被拒绝用户'root'@'localhost'(使用密码:YES)

时间:2021-12-03 19:19:06

I'm kind of new with symfony and I'm trying to create a entity in through doctrine, I'm working on Windows and xampp.

我是symfony的新手,我正试图通过学说创建一个实体,我正在研究Windows和xampp。

In one cmd I have the server running (php bin/console server:run) in another cmd I tried to create the entity with php bin/console doctrine:generate:entity

在一个cmd我有服务器运行(php bin / console server:run)在另一个cmd我试图用php bin / console doctrine创建实体:generate:entity

It asks my for a entity shortcut name (BlogBundle:Post) after this I get three the same kind of errors;

它询问我的实体快捷方式名称(BlogBu​​ndle:Post)之后我得到三个相同类型的错误;

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

I googled and found that, because I already have databases in xampp, and changed the password. therefor I should change my password in the parameters.yml, which I did ( I also created an empty symfony database in phpMyAdmin);

我用谷歌搜索,发现,因为我已经在xampp中有数据库,并更改了密码。因此我应该在parameters.yml中更改我的密码,我做了(我还在phpMyAdmin中创建了一个空的symfony数据库);

# This file is auto-generated during the composer install
parameters:
    database_host: 127.0.0.1
    database_port: null
    database_name: symfony
    database_user: root
    database_password: mypassword
    mailer_transport: smtp
    mailer_host: 127.0.0.1
    mailer_user: null
    mailer_password: null
    secret: ac8be0befa84f2aeda5d2e9068a7ae2e948376fb

My doctrine part of my config.yml file looks like this;

我的config.yml文件的学说部分看起来像这样;

# Doctrine Configuration
doctrine:
    dbal:
        driver: pdo_mysql
        host: '%database_host%'
        port: '%database_port%'
        dbname: '%database_name%'
        user: '%database_user%'
        password: '%database_password%'
        charset: UTF8
        # if using pdo_sqlite as your database driver:
        #   1. add the path in parameters.yml
        #     e.g. database_path: "%kernel.project_dir%/var/data/data.sqlite"
        #   2. Uncomment database_path in parameters.yml.dist
        #   3. Uncomment next line:
        #path: '%database_path%'

    orm:
        auto_generate_proxy_classes: '%kernel.debug%'
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true

After this I still get the three errors, only 'password: no' changed to 'password: yes';

在此之后我仍然得到三个错误,只有'密码:否'改为'密码:是';

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

Can someone tell me whats going wrong and what I should change?

有人能告诉我什么是错的,我应该改变什么?

I already tried everything in SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: NO) . changing host from 127.0.0.1 to localhost, changing port to 3306, putting the password in quotes and the SonataUserBundle part doesn't applies here.

我已经在SQLSTATE中尝试了所有内容[28000] [1045]访问被拒绝用户'root'@'localhost'(使用密码:NO)。将主机从127.0.0.1更改为localhost,将端口更改为3306,将密码放在引号中,SonataUserBundle部分不适用于此处。

1 个解决方案

#1


2  

i had the same error thrown mysql, the solution is to wrapping password in single quote

我有同样的错误抛出mysql,解决方案是在单引号中包装密码

    database_password: 'mypassword' 

#1


2  

i had the same error thrown mysql, the solution is to wrapping password in single quote

我有同样的错误抛出mysql,解决方案是在单引号中包装密码

    database_password: 'mypassword'