cancel
Showing results for 
Search instead for 
Did you mean: 

SQLSTATE[HY000] [1045] Access denied for user 'magento'@'localhost'

SQLSTATE[HY000] [1045] Access denied for user 'magento'@'localhost'

Hi all,

 

I'm banging my head against the wall trying to figure out what I did wrong. I've created a database and a user, but when I run the installation, I get the following error.

 

magento install error.png

 

And yes, I checked and rechecked the password a thousand times. I'm hoping one of you kind souls can point out my obvious mistake.

 

Sigh... I'll just keep checking the password until I hear back...

 

Thanks!

11 REPLIES 11

Re: SQLSTATE[HY000] [1045] Access denied for user 'magento'@'localhost'

1. Check that DB grant all permission.
2. Check your host is same or different.
3. Check the database allocated to the particular user or not.
mysql -u [username] -p (using command prompt)
4. show Databases (In that list check your DB exist or not)

Re: SQLSTATE[HY000] [1045] Access denied for user 'magento'@'localhost'

Hello! Thanks for the reply!

As you can see from the screenshot, I've done all those things. Unless I'm
missing something. Please double check me!

1. The screenshot shows that all privileges have been granted ("GRANT ALL
PRIVILEGES").
2. The screenshot shows that 'localhost' is used in all places
("'magento'@'localhost'"
and "db-name=localhost")
3. The screenshot shows that the user 'magento'@'localhost' has all
privileges on magento.* . Using the command prompt, I AM ABLE to log in as
magento, using my specified password.
4. Yes, when logged in via command prompt, and I do 'show databases;', I
see the magento database.

Again, thanks for all your help!

Re: SQLSTATE[HY000] [1045] Access denied for user 'magento'@'localhost'

The user "root" doesn't have permission to access your database from that IP. I recommend creating a user specifically for Magento

 

Follow these steps: SQLSTATE[HY000] [1045] Access denied for user

 

I hope it helps!

If Issue Solved, Click Kudos/Accept As solutions.

Re: SQLSTATE[HY000] [1045] Access denied for user 'magento'@'localhost'

I'm not using the user "root" anywhere. Can you please point out where you
think I might be? Thanks!

Re: SQLSTATE[HY000] [1045] Access denied for user 'magento'@'localhost'

Hi @drexlin

Please try once 127.0.0.1 instead of localhost once in app/etc/env.php

Re: SQLSTATE[HY000] [1045] Access denied for user 'magento'@'localhost'

Thank you, @Vimal Kumar . I did try putting 127.0.0.1 in the command line arguments, with no luck. Do you mean to say I need to edit the env.php file? And can you explain the difference between using 127.0.0.1 and localhost?

 

Either way, I won't be able to test it right way because...

 

UPDATE: I was able to work around the issue by using the Setup Wizard instead. It had no issues connecting to the database using the credentials I provided.

 

However, even though I found a workaround, I would like to keep the discussion going. There is no reason (in my opinion) that the command line method would not work. Is there an argument I got wrong? Is there a permissions issue? What system user (as opposed to database user) does the Setup Wizard use to access the database? I'm guessing it's not the 'magento' user that I used to execute the command line command.

 

Thoughts? Thanks for your input!

Re: SQLSTATE[HY000] [1045] Access denied for user 'magento'@'localhost'

Yes,
I mean to edit env.php and add 127.0.0.1 there instead of localhost.

127.0.0.1 is the ip address of localhost.
Some server unable to connect db using localhost, but it works using ip 127.0.0.1

Re: SQLSTATE[HY000] [1045] Access denied for user 'magento'@'localhost'

If you have special character on password then add back slash, for example if your password is admin$33^p then write password as admin\$33\^p this will work

Re: SQLSTATE[HY000] [1045] Access denied for user 'magento'@'localhost'


@kmrafiq wrote:

If you have special character on password then add back slash, for example if your password is admin$33^p then write password as admin\$33\^p this will work


This worked for me!

 

Thanks a lot!