13

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

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:

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.

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

nyedidikeke
  • 6,899
  • 7
  • 44
  • 59
mentaga
  • 131
  • 1
  • 1
  • 4
  • 6
    Access denied for user 'root'@'localhost' (using password: YES) is a MySQL connection error. Usually implies invalid user and/or password. Sometimes you have to use localhost not 127.0.0.1 for this to work. – Ryan May 01 '13 at 19:38
  • 1
    Is the password in quotes? – Emii Khaos May 01 '13 at 22:15

8 Answers8

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"
Pier-Luc Gendreau
  • 13,553
  • 4
  • 58
  • 69
6

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

   app/console cache:clear --env=prod
iarroyo
  • 2,354
  • 24
  • 23
4

In your 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_password should be within double or single quotes as in: "your_password" or 'your_password'.

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

nyedidikeke
  • 6,899
  • 7
  • 44
  • 59
Nadun Liyanage
  • 434
  • 3
  • 5
  • 1
    Indeed @Nadun Liyanage is actually right, password database should be between "" like this for example `"0000"`, because it's a string. – french_dev Mar 28 '16 at 10:38
  • He IS right indeed. Wow thanks! Strangely enough the built-in server of Symfony 3 accepted without quotes. Using nginx I really needed this quotes otherwise it didn't work --> Access denied for user issue. – Melroy van den Berg May 05 '16 at 23:19
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.

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.

Doug
  • 1,850
  • 23
  • 50
2

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

  • The MySQL SET PASSWORD command:

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

    mysqladmin -u root -pCURRENTPASSWORD password ''
    
Pang
  • 9,564
  • 146
  • 81
  • 122
sofiane
  • 31
  • 3
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.

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.

Hope this helps.

0

It could be that the username and password are not what you think they are. If your domain provider sent you a credentials email when you purchased it, the username and password are the ones in there. Not what you might have set up through cPanel or PHPmyAdmin/SQL etc. It will be your cPanel password for that domain name.

Robert Yeomans
  • 192
  • 1
  • 4
0

I had the same problem and fixed it by changing 127.0.0.1 to localhost

Codeparl
  • 300
  • 1
  • 8