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

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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

#1 User is offline   ohgod 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 01-November 17

Posted 01 November 2017 - 06:46 PM

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' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=your-db',
'username' => 'your-username',
'password' => 'your-pwd',
'charset' => '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
0

#2 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,828
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 01 November 2017 - 07:08 PM

Add permissions for user to the db table.
Don't forget to read The Definitive Guide to Yii (1.1 en) (1.1 sv) (2.0 en) | The class reference (1.1) (2.0) has the details
0

#3 User is offline   ohgod 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 01-November 17

Posted 12 November 2017 - 08:28 PM

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)
0

#4 User is offline   thadude 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 14-August 12

Posted 12 January 2018 - 07:02 AM

did you initialize the environment?

php init
0

#5 User is offline   ohgod 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 01-November 17

Posted 14 January 2018 - 09:01 PM

View Postthadude, on 12 January 2018 - 07:02 AM, said:

did you initialize the environment?

php init


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

#6 User is offline   Stefano Mtangoo 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 363
  • Joined: 02-January 12
  • Location:Dar es Salaam, Tanzania

Posted 17 January 2018 - 05:34 AM

It means you are using wrong username or password
And God said, Let there be science...and it was so! Jukwaa la wanaoongea Kiswahili Hapa, and its github repo here
0

#7 User is offline   Roberto Braga 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 211
  • Joined: 18-February 13
  • Location:Roma, Italy

Posted 18 January 2018 - 01:07 PM

Quote

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

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
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users