Grow your CSS skills. Land your dream job.

[Solved] Only connect to MySQL as "root" user/no password

  • # August 9, 2009 at 11:45 pm

    Hello all. I’m writing today because I’ve got a bit of a problem, and I was hoping your collective brains could help me find where I’ve gone wrong.

    I’m working on a MySQL/PHP based website, to see if I can get beyond the "hello world" stage of my php programming, and my first main obstacle is in my database connection. Before I get to the problem, here’s my tech setup/info:

    • I’m using WAMP for local development[/*:m]
    • I’ve created a new database in PHPMyAdmin called "rie_database" to store my site info[/*:m]
    • I’ve created a user, "rie_admin," with password "xyz" (not really, but the real one is rather complicated)[/*:m]
    • I’ve given "rie_admin" all database specific DATA, STRUCTURE, and ADMINISTRATION privileges, but no globals[/*:m][/list:u]
      I’ve created a simple "config.php" file like so:

      Code:
      < ?php
      $dbhost = "localhost";
      $dbuser = "rie_admin";
      $dbpassword = "xyz";
      $dbdatabase = "rie_database";
      ?>

      which then feeds into the following php:

      Code:
      < ?php
      $db = mysql_connect($dbhost, $dbuser, $dbpassword) or die(mysql_error());
      mysql_select_db($dbdatabase, $db);
      ?>

      When I try to view the page, I get an error saying:

      Quote:
      Warning: mysql_connect() [function.mysql-connect]: Access denied for user ‘rie_admin’@’localhost’ (using password: YES) in C:wampwwwrie_sitephp_scriptsheader.php on line 7
      Access denied for user ‘rie_admin’@’localhost’ (using password: YES)

      where line 7 is

      Code:
      $db = mysql_connect($dbhost, $dbuser, $dbpassword) or die(mysql_error());

      If, however, I set the config file to

      Code:
      $dbhost = “localhost”;
      $dbuser = “root”;
      $dbpassword = “”;
      $dbdatabase = “rie_database”;

      it connects without any problem.
      Any idea why this is happening? Or even better, how to fix it? I’ve tried giving rie_admin global privileges, with no change in the error. My Google-fu has also failed me. I know I could just keep developing using the root/no password setup, but as this is supposed to be more of an educational/mastering-php/mysql kind of thing, I thought it better to learn what’s going on.

      Thanks in advance for any help.

      P.S., as this is my first post, and I hope to be a contributor as well as a help seeker on this forum, I thought it appropriate to introduce myself. Hi. My name’s Warren.

    # August 10, 2009 at 1:01 pm

    Hi Warren,

    I’m afraid I don’t have any particular answers for you =(. That stuff confuses me too. I do know that that kind of stuff is precicely why I don’t use MAMP (or any of the others) to develop locally. There is too much confusing when then trying to move it live. I’m sure smarter people than us laugh, but whatever. If I develop online, on the same server the real site will be on, I know I won’t have any problems.

    # August 10, 2009 at 1:47 pm

    Not wishing to be facetious but you said

    Quote:
    with password "xyz" (not really, but the real one is rather complicated)

    If it is that complicated are you 100% sure you have the right password? Did you get it right when you created the user? Try setting up another user with a simple password and see if that works.

    # August 10, 2009 at 2:47 pm
    "apostrophe" wrote:
    Not wishing to be facetious but you said

    Quote:
    with password "xyz" (not really, but the real one is rather complicated)

    If it is that complicated are you 100% sure you have the right password? Did you get it right when you created the user? Try setting up another user with a simple password and see if that works.

    hmm…
    *goes and fiddles*
    No luck. I tried setting the password literally to "xyz" with no change. It was worth a shot though, so thanks regardless.

    # August 10, 2009 at 6:18 pm

    Hi Warren, sounds like a real tough one. Only thing I can suggest is to (using mysql console):

    Code:
    SHOW GRANTS FOR ‘rie_admin’@’localhost';
    | GRANT USAGE ON *.* TO ‘rie_admin’@’localhost’ IDENTIFIED BY PASSWORD ‘*xxxxxxx’ |
    | GRANT ALL PRIVILEGES ON `xxz.* TO ‘rie_admin’@’localhost’

    There should be a minimum of GRANT USAGE and also a grant on the specific database. This might at least give you some insight as to why it’s not working.

    Hope that at least points you in the right direction.

    Cheers
    Dave

    # August 10, 2009 at 6:43 pm

    I tried putting in the SHOW GRANTS code Dave suggested, and here’s the result:

    Code:
    GRANT USAGE ON *.* TO ‘rie_admin’@’localhost’ IDENTIFIED BY PASSWORD ‘*33B798A40786F2EE830BF8A49267EF566327D5A1′
    GRANT ALL PRIVILEGES ON `rie_database`.* TO ‘rie_admin’@’localhost’ WITH GRANT OPTION

    It looks pretty much like what Dave suggested it should, but the password is rather convoluted, and not anything I’ve ever typed in. Is it normal for phpmyadmin to encrypt a password like that? Or might that be my problem, and if so, how might I fix it?

    And thanks again for all the help.

    # August 11, 2009 at 3:34 pm

    Well, after much searching, fiddling, and generalized cranium-to-brick-wall application, I’ve finally got the issue resolved. It turns out, I was having the same problem that this guy was having. After tweaking my "Any" user as described in the aforelinked thread, the connection is now working fine. I feel kind of stupid actually, for taking so long to find it, but I was sure I was having a PHPMyAdmin problem, rather than a straight MySQL problem. Live and learn, I guess :roll: .

    And thanks again, to all who applied some intellect to this issue for me.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".