Access denied for user ''@'localhost'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #16
    Can you verify that the connection code is being run?

    The reason I ask is that PHP is reporting the 'access denied' error is being triggered by mysql_query(), not mysql_connect() , which would lead me to believe that at the time your script attempts to call mysql_query(), the connection has not been established.

    PHP will attempt to establish a connection using the default values specified in php.ini, which is usually maybe a Username, and that's it. I'm thinking that's what happened based on the "using password NO" part.

    Comment

    • Strika Amaru
      New Member
      • May 2007
      • 19

      #17
      You might laugh at this.

      I took up pbmods' advice, and tried to mess around the connection code. Around it, not with it. I've:

      * put echoes in getMySQLConnect ion, one right before returning the connection, the other before throwing the exception.
      * commented out:
      $mySqlConnectio n = getMySQLConnect ion(); and put
      $mySqlConnectio n = mysql_connect( "...", "...", "..." ) or die( "Connection Error: " . mysql_error());
      with the params hardcoded.
      * went in Notepad++ and search-highlighted every occurrence of $mySqlConnectio n - just in case I have a typo.
      * copy/pasted the SELECT from login.php, hardcoded the username and tried to print on page.
      U-oh! Same error as from the INSERT. So I look between mysql_select_db and selectQuery. The only notable thing there was:

      Code:
       if( [B]hasUserName[/B]( $safeUserName ) ){
      Thing was, the script was pretty much having its cake and eating it, too. All connection, db open, etc. code was correct.

      But hasUserName:
      - connects to the db,
      - executes "SELECT UserName FROM Users WHERE UserName = '" . $safeUserName . "';",
      - CLOSES THE CONNECTION
      - and returns true or false.

      After calling it, there's no more connection.

      I moved the connecting on the "else" branch, and that's it.

      Comment

      • cl578
        New Member
        • Sep 2009
        • 2

        #18
        Originally posted by pbmods
        Heya, Markodilore.

        To log into MySQL, use this:
        Code:
        /usr/local/mysql/bin/mysql -u root -p
        I know that the initial post is from 2 years ago, but I would like to say Thank You so much for answering this question. This answer really helped me and as a result, I am now a member of the website, which is not something I normally do...

        Thank You, again!

        Comment

        • tg3793
          New Member
          • Dec 2009
          • 1

          #19
          MySQL root access on a Windows XP machine

          Originally posted by pbmods
          Heya, Markodilore.

          To log into MySQL, use this:
          Code:
          /usr/local/mysql/bin/mysql -u root -p
          I would like to thank you SO MUCH for posting this information and caring so much about helping others with this. Now, over two years later I am able to make great use of this.

          I am not a "spring chicken" when it comes to IT by any means. And I'd like to think that I am in the top one or two percent of people that I've ever known when it comes to tracking down the answer to IT related problems. Would you believe it took me about three hours of focussed effort to find that simple answer you gave here.

          That's right; several dozen websites (including blogs and forums), doing searches through the html version of the MySQL users manual, and even a question that I posted to the #mysql IRC channel (which no one ever answered).


          And for the future edification of anyone else that might come to this, I had to make a very slight modification to the answer that was given here because I am on a Windows XP machine. I installed vTiger which automatically installed MySQL within it's installation. So I typed the following:

          C:\Program Files\vtigercrm-5.1.0\mysql\bin \mysql -u root -p

          From there it prompted me for the root password and I was home free. ..Again, thank you thank you thank you.

          Comment

          • dhanush

            #20
            guys, I had a same problem and I was searching for this solution, thank god, you guys saved my temper as well ... thanks it works
            Last edited by MMcCarthy; Oct 21 '10, 09:37 AM. Reason: proper English please

            Comment

            Working...