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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16325115/
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-31 17:30:48  来源:igfitidea点击:

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

mysqlubuntusymfony

提问by mentaga

I tried to create my DB with Symfony2 typing the command below:

我尝试使用 Symfony2 创建我的数据库,并输入以下命令:

php app/console doctrine:create:database

The result is:

结果是:

Could not create database for connection named jobeetSQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: YES)

无法为名为jobeetSQLSTATE [28000] [1045] 用户“root”@“localhost”的访问被拒绝(使用密码:YES)创建数据库

The contents of my app/config/parameters.ymlfile is:

我的app/config/parameters.yml文件的内容是:

parameters:
   database_driver:   pdo_mysql
   database_host:     127.0.0.1
   database_port:     ~
   database_name:     jobeet
   database_user:     root
   database_password: 0000

   mailer_transport:  smtp
   mailer_host:       127.0.0.1
   mailer_user:       ~
   mailer_password:   ~

   locale:            fr
   secret:            ThisTokenIsNotSoSecretChangeIt

My OS is Ubuntu.

我的操作系统是 Ubuntu。

I don't know what to do to correct this problem.

我不知道该怎么做才能纠正这个问题。

回答by Pier-Luc Gendreau

Try to login via the terminal using the following command:

尝试使用以下命令通过终端登录:

mysql -u root -p

It will then prompt for your password. If this fails, then definitely the username or password is incorrect. If this works, then your database's password needs to be enclosed in quotes:

然后它会提示您输入密码。如果失败,那么肯定是用户名或密码不正确。如果这有效,那么您的数据库密码需要用引号括起来:

database_password: "0000"

回答by iarroyo

I dont know what is the exact reason but I solved the problem running:

我不知道确切的原因是什么,但我解决了运行的问题:

   app/console cache:clear --env=prod

回答by Nadun Liyanage

In your app/config/parameters.yml

在你的 app/config/parameters.yml

# This file is auto-generated during the composer install
parameters:
    database_driver: pdo_mysql
    database_host: 127.0.0.1
    database_port: 3306
    database_name: symfony
    database_user: root
    database_password: "your_password"
    mailer_transport: smtp
    mailer_host: 127.0.0.1
    mailer_user: null
    mailer_password: null
    locale: en
    secret: ThisTokenIsNotSoSecretChangeIt

The value of database_passwordshould be within double or single quotes as in: "your_password"or 'your_password'.

的值database_password应该在双引号或单引号内,如:"your_password"'your_password'

I have seen most of users experiencing this error because they are using password with leading zero or numeric values.

我见过大多数用户遇到此错误,因为他们使用的密码带有前导零或数字值。

回答by sofiane

You need to set the password for root@localhostto be blank. There are two ways:

您需要将密码设置为root@localhost空白。有两种方式:

  • The MySQL SET PASSWORDcommand:

    SET PASSWORD FOR root@localhost=PASSWORD('');
    
  • Using the command-line mysqladmintool:

    mysqladmin -u root -pCURRENTPASSWORD password ''
    
  • MySQLSET PASSWORD命令:

    SET PASSWORD FOR root@localhost=PASSWORD('');
    
  • 使用命令行mysqladmin工具:

    mysqladmin -u root -pCURRENTPASSWORD password ''
    

回答by Doug

Ok, so this might not fix your issue but it definitely worked for me.

好的,所以这可能无法解决您的问题,但它绝对对我有用。

So you've created your Mysql user I take it? Go to user privileges on PhpMyAdmin and click edit next to the user your using for Symfony. Scroll down to near the bottom and where it says which host you want to use make sure you've selected LocalHost not % Any.

所以你已经创建了你的 Mysql 用户我拿它吗?转到 PhpMyAdmin 上的用户权限,然后单击您用于 Symfony 的用户旁边的编辑。向下滚动到底部附近,在那里显示您要使用的主机,请确保您选择了 LocalHost 而不是 % Any。

Then in your config file swap 127.0.0.1 for localhost. Hopefully that will work for you. Just worked for me as I was having the same issue.

然后在你的配置文件中为 localhost 交换 127.0.0.1。希望这对你有用。刚刚为我工作,因为我遇到了同样的问题。

回答by user4164558

I was having similar issues connecting to OpenSUSE 13.1 MySQL database with LibreOffice. Update LibreOffice to latest stable "Still" package, then make sure the database is accessible using a tool such as phpMyAdmin. Make sure your user is linked to localhost and not "%" (any). This worked for me, I am able to add data thru LibreOffice.

我在使用 LibreOffice 连接到 OpenSUSE 13.1 MySQL 数据库时遇到了类似的问题。将 LibreOffice 更新到最新的稳定“Still”包,然后确保可以使用 phpMyAdmin 等工具访问数据库。确保您的用户链接到 localhost 而不是“%”(任何)。这对我有用,我可以通过 LibreOffice 添加数据。

Side note - LibreOffice Base will not supply "native connection" via MySQL on first attempt, you will need to use the back button, then try again to see the options.

旁注 - LibreOffice Base 不会在第一次尝试时通过 MySQL 提供“本机连接”,您需要使用后退按钮,然后再试一次以查看选项。

Hope this helps.

希望这可以帮助。