Exception 'yii\db\Exception' with message 'SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)'

What steps will reproduce the problem?

following tutorial code(dot)tutsplus(dot)com /tutorials/building-your-startup-with-php-feature-requirements-and-database-design–cms-22618

install yii, make a database, user, put the credentials in \environments\dev\common\main-local.php

<?php

return [

'components' =&gt; [


    'db' =&gt; [


        'class' =&gt; 'yii&#092;db&#092;Connection',


        'dsn' =&gt; 'mysql:host=localhost;dbname=your-db',


        'username' =&gt; 'your-username',


        'password' =&gt; 'your-pwd',


        'charset' =&gt; 'utf8',


    ],

then run ./yii migrate/up 1

What is the expected result?

Creating migration history table "migration"…done.

Total 1 out of 15 new migrations to be applied:

What do you get instead?

Error: SQLSTATE[28000] [1045] Access denied for user ‘root’@‘localhost’ (using password: YES)

on clearlinux web server

-or-

Exception ‘yii\db\Exception’ with message ‘SQLSTATE[HY000] [1045] Access denied for user ‘root’@‘localhost’ (using password: YES)’

on Ubuntu localhost

Additional info

Q A

Yii version 2.0.?

PHP version 5.6.31 and/or 7.1.8

Operating system Ubuntu 17.10 and/or CloudLinux

Add permissions for user to the db table.

You’re gonna have to be really specific. I of course GRANTED all permissions to root and my user, and FLUSHED privileges.

If I run

GRANT ALL PRIVILEGES ON ‘dbname’ TO ‘usernameicreated’@‘localhost’

or

GRANT ALL PRIVILEGES ON ‘dbname’.* TO ‘usernameicreated’@‘localhost’

I get no response. It just goes to another line with prompt > like nothing happened.

Here are the permissions:

*************************** 1. row ***************************

             Host: localhost


               Db: dbname


             User: root


      Select_priv: Y


      Insert_priv: Y


      Update_priv: Y


      Delete_priv: Y


      Create_priv: Y


        Drop_priv: Y


       Grant_priv: N


  References_priv: Y


       Index_priv: Y


       Alter_priv: Y

Create_tmp_table_priv: Y

 Lock_tables_priv: Y


 Create_view_priv: Y


   Show_view_priv: Y

Create_routine_priv: Y

Alter_routine_priv: Y

     Execute_priv: Y


       Event_priv: Y


     Trigger_priv: Y

1 row in set (0.00 sec)

*************************** 1. row ***************************

             Host: localhost


               Db: dbname


             User: usernameicreated


      Select_priv: Y


      Insert_priv: Y


      Update_priv: Y


      Delete_priv: Y


      Create_priv: Y


        Drop_priv: Y


       Grant_priv: N


  References_priv: Y


       Index_priv: Y


       Alter_priv: Y

Create_tmp_table_priv: Y

 Lock_tables_priv: Y


 Create_view_priv: Y


   Show_view_priv: Y

Create_routine_priv: Y

Alter_routine_priv: Y

     Execute_priv: Y


       Event_priv: Y


     Trigger_priv: Y

1 row in set (0.00 sec)

did you initialize the environment?

php init

Yes. Tried as both dev and prod environments, followed the tutorial.

It means you are using wrong username or password

I guess you are talking about MySQL console. This is because you miss ; at the end of your SQL command

To check if db permission are fine try using mysql via shell

mysql -u <username> -p<password> <dbname>

Note that after -p there is no space

If you can connect via shell the problem is in yii config

Hi friends i got the same issue, but i don’t use password in the phpmyadmin

i want to learn yii2, and try to install basic template project.
and the first things that i want to make is a migration.
but i got some issue that i can’t fix, already try to search the solution.
i guess i don’t have problem in phpmyadmin

but i got error when i try to make migration in yii2,

i use vscode to ru n the command line, and xampp for the server.

so what do you think for this issue, please help me to fix this error.

this is my phpmyadmin user account

Hi David, Please open new thread when you have a problem instead of writing on top of existing thread.

As error says you have wrong credentisla in your config/db.php file. Fix that and it will work