9

I have a common problem but the usual solutions are not working so apologies for what on first appearance may seem like a previously asked question.

I have the following error when trying to view my site on my local

    Access denied for user 'sitename'@'localhost' (using password: YES)

The credentials being used wrong but I don't know where they are coming from. I have checked app/etc/local.xml and it has all correct credentials. I have removed all other xml files from the directory (except config.xml). I have deleted the contents of the var folder (numerous times)

I have other magento sites working on my local so my server settings should be fine. I'm really stumped on this and don't know what next step I should take. Any help would be appreciated.

  • I would go to the connect method in DB adapter and right before the call to the connection method, place something like: '$e = new Exception(); Mage::log($e->getTraceAsString(), null, 'logname', true);' getting trace like this is more compact. Then in that trace see for any odd code paths. Also log actual credentials that are passed to PDO. – Petar Dzhambazov Oct 14 '13 at 17:24
8

You need to make the user sitename@localhost able to access the database and tables in question. Use the following SQL as a root or superuser on the MySQL instance to grant the privileges:

GRANT ALL ON magento_local.* TO 'sitename'@'localhost';

For more information on Grants in MYSQL see the manual: http://dev.mysql.com/doc/refman/5.1/en/grant.html

  • Thanks for the answer. I came across this option earlier but i didn't think it would work. Because user:'sitename' and pass:'yes' are not the correct/specified db credentials I assumed this does not really solve the issue of wrong details being used or can it somehow find the details in app/etc/local.xml after being able to connect to the db once with the wrong details – develophper Oct 14 '13 at 18:40
  • There's a difference between accessing mysql directly and over 'localhost' which is via network. You need to grant explicitly on the localhost location. – philwinkle Oct 14 '13 at 18:48
  • 2
    remember and run:flush privilegesafter your grant command – Matthew Haworth Mar 6 '15 at 12:13
5

In case local.xml is being overridden search your site for files containing something like <username>sitename</username>. For this sort of work I prefer ack:

ack --xml "<username>.*sitename.*</username>" app/

...or even just:

ack sitename app/
4

Try to clear cache, maybe you are using 3rd party caching layers, disable them. Last option is rename app/etc/local.xml and open website, Magento should run installation process, during installation provide old encryption key from local.xml.

1

All of the other answers were a great way to narrow down all of the possibilities as to what the issue could have been. For this I felt each of them deserved an up vote. They did not directly solve my problem so I felt I should give an answer myself as a courtesy and also because a lot of people use wordpress with magento.

This particular site uses wordpress as a module. This module contains db credentials as well as the usual magento app/etc/local.xml. I was not aware that this module is rendered pretty much all over the site and is relevant to the database. As a result it made it impossible to view the site without changing the details in here too.

0

I had the same problem, following solved this for me:

  1. Download the original version of Magento
  2. backup your app/etc (ex.: app/_etc)
  3. Upload the original app/etc from the original Magento folder
  4. Go to your site and do the Magento installation process, I used my original database name, database settings (user/pw) and encryption key.
  5. Upload your app/etc/modules into the new ETC folder
  6. After installation I could login and clear cache. The website was working again like before.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.