cancel
Showing results for 
Search instead for 
Did you mean: 

SQLSTATE[HY000] [1045] Access denied for user 'magento'@'localhost' (using password: YES)

SQLSTATE[HY000] [1045] Access denied for user 'magento'@'localhost' (using password: YES)

Hello.

I want to install Magento 2.X wiuth below command:

 ./magento setup:install --admin-firstname="name" --admin-lastname="family" --admin-email="example@example.com" --admin-user="jason" --admin-password="jason" --db-name="store" --db-host="localhost" --db-user="magento" --db-password="PASS"

but I got below error:

SQLSTATE[HY000] [1045] Access denied for user 'magento'@'localhost' (using password: YES)

I checked the "magento" user permission and it is like below:

MariaDB [(none)]> SHOW GRANTS FOR 'magento'@'localhost';
+------------------------------------------------------------+
| Grants for magento@localhost                               |
+------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'magento'@'localhost'                |
| GRANT ALL PRIVILEGES ON `store`.* TO 'magento'@'localhost' |
+------------------------------------------------------------+
2 rows in set (0.00 sec)

What is my problem?

 

Thank you.

20 REPLIES 20

Re: SQLSTATE[HY000] [1045] Access denied for user 'magento'@'localhost' (using password: YES)

Hi @jason_long,
Please check once your database access using username and password.
You can also check using GUI file (adminer.php). You can download from following url:
https://github.com/intrd/php-adminer

If it fine then please try once using "127.0.0.1" instead of "localhost".


Re: SQLSTATE[HY000] [1045] Access denied for user 'magento'@'localhost' (using password: YES)

Hello @jason_long 

 

can you please check if that user added for that DB?

 

 

 

 


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: SQLSTATE[HY000] [1045] Access denied for user 'magento'@'localhost' (using password: YES)

Hello @jason_long 

 

I myself faced this issue few days back. This is because your mysql is having some password set for root. And in your case it doesnt get the password that is why it is showing this error. Can you tell me what platform are you using xampp or lamp?

 

Re: SQLSTATE[HY000] [1045] Access denied for user 'magento'@'localhost' (using password: YES)

Yes, I set password for "root" . I'm using lamp. How can I solve it?

Re: SQLSTATE[HY000] [1045] Access denied for user 'magento'@'localhost' (using password: YES)

@jason_long , You have to create database 1st from command line or PHPMyAdmin. After creating database, run below command to install using command line.

 

 

php bin/magento setup:install --base-url=http://127.0.0.1/magento2/ \ --db-host=localhost --db-name=rock --db-user=root --db-password= \ --admin-firstname=Magento --admin-lastname=User --admin-email=user@example.com \ --admin-user=admin --admin-password=admin123 --language=en_US \ --currency=USD --timezone=America/Chicago --use-rewrites=1

Re: SQLSTATE[HY000] [1045] Access denied for user 'magento'@'localhost' (using password: YES)

I changed "db-user" to "root" and got another error about MySQL version:

Sorry, but we support MySQL version 5.6.0 or later.

MySQL version is :

$ mysql -V
mysql  Ver 15.1 Distrib 5.5.60-MariaDB, for Linux (x86_64) using readline 5.1

Why I must use "root" user? I created a user for my DB.

Re: SQLSTATE[HY000] [1045] Access denied for user 'magento'@'localhost' (using password: YES)

I upgrade "MariaDB" and problem solved but why "root" user?

Magento show me:

[SUCCESS]: Magento installation complete.
[SUCCESS]: Magento Admin URI: /admin_175s6i
Nothing to import.

When I browse "http://Server_IP/admin_175s6i" then I can't see anything!!!

Re: SQLSTATE[HY000] [1045] Access denied for user 'magento'@'localhost' (using password: YES)

Can anyone answer me?

Re: SQLSTATE[HY000] [1045] Access denied for user 'magento'@'localhost' (using password: YES)

You should add port your DB, for example
instead
--
db-host="localhost"
use
--db-host="127.0.0.1:8889"