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

时间:2022-10-02 19:17:01

I tried to create my DB with Symfony2. I typed the command:

我尝试用Symfony2创建DB。我输入命令:

php app/console doctrine:create:database

The result is:

其结果是:

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

The contents of my app/config/parameters.yml file is:

我的应用程序/配置/参数的内容。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.

我不知道怎样才能解决这个问题。

Thanks for your help.

谢谢你的帮助。

6 个解决方案

#1


12  

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"

#2


6  

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

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

   app/console cache:clear --env=prod

#3


3  

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

database_password should be inside double quoted (") or single quoted (').

database_password应该在双引号(")或单引号(')内。

I have seen most of users happen this because they are using password with leading zero or numeric (in my situation its like that)

我看到大多数用户都是这样做的,因为他们使用的密码是零或数字(在我的情况下是这样)

#4


2  

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的用户旁边的edit。向下滚动到接近底部的地方,它告诉您要使用哪个主机,确保您已经选择了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。希望这对你有用。只是为我工作,因为我也有同样的问题。

#5


2  

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

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

  • The MySQL SET PASSWORD command:

    MySQL设置密码命令:

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

    使用命令行sqmyladmin工具:

    mysqladmin -u root -pCURRENTPASSWORD password ''
    

#6


0  

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.

我有类似的问题连接到OpenSUSE 13.1 MySQL数据库和LibreOffice。将LibreOffice更新为最新的稳定“Still”包,然后使用phpMyAdmin之类的工具确保数据库是可访问的。确保您的用户链接到localhost,而不是“%”(any)。这对我很有效,我可以通过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基本版不会在第一次尝试时通过MySQL提供“本机连接”,您需要使用back按钮,然后再尝试查看选项。

Hope this helps.

希望这个有帮助。

#1


12  

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"

#2


6  

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

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

   app/console cache:clear --env=prod

#3


3  

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

database_password should be inside double quoted (") or single quoted (').

database_password应该在双引号(")或单引号(')内。

I have seen most of users happen this because they are using password with leading zero or numeric (in my situation its like that)

我看到大多数用户都是这样做的,因为他们使用的密码是零或数字(在我的情况下是这样)

#4


2  

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的用户旁边的edit。向下滚动到接近底部的地方,它告诉您要使用哪个主机,确保您已经选择了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。希望这对你有用。只是为我工作,因为我也有同样的问题。

#5


2  

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

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

  • The MySQL SET PASSWORD command:

    MySQL设置密码命令:

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

    使用命令行sqmyladmin工具:

    mysqladmin -u root -pCURRENTPASSWORD password ''
    

#6


0  

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.

我有类似的问题连接到OpenSUSE 13.1 MySQL数据库和LibreOffice。将LibreOffice更新为最新的稳定“Still”包,然后使用phpMyAdmin之类的工具确保数据库是可访问的。确保您的用户链接到localhost,而不是“%”(any)。这对我很有效,我可以通过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基本版不会在第一次尝试时通过MySQL提供“本机连接”,您需要使用back按钮,然后再尝试查看选项。

Hope this helps.

希望这个有帮助。