SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Chennai
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unable to Connect Mysql Server

    Warning: mysql_connect() [function.mysql-connect]: Access denied for user: 'root@localhost' (Using password: YES) in D:\Program Files\Apache Group\Apache2\htdocs\123\mydb.php on line 2
    Could not connect: Access denied for user: 'root@localhost' (Using password: YES)

    can Someone help me to sort out this error

  2. #2
    SitePoint Wizard rbutler's Avatar
    Join Date
    Jul 2003
    Location
    Springfield, MO
    Posts
    1,867
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It means root@localhost doesn't have permissions to the database. I wouldn't use this account anyway. Go into your control panel and set up another user name and password. Never use the admin account for general access, you're exposing yourself and app to unnecessary security risks. Modify your connection string to account for you new username and password, if it was foo for username and cat for password then look below:

    Code:
    $db=mysql_connect("localhost", "foo", "cat") or die ("Can't connect to mysql because" . mysql_error());
    Ryan Butler

    Midwest Web Design

  3. #3
    SitePoint Member Aber_Al's Avatar
    Join Date
    Dec 2004
    Location
    Wales
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    This may be stupid but...

    Have you made sure the password is correct? mysql sets the root password to null when you first set it up (ie installed with no password on root a/c) and you must set the permissions tables yourself (it's the 'identified by...' bit you need - look in the mysql manual, think it's at the granting priviliges section I forget exactly now).

    Does this help?

  4. #4
    SitePoint Member Aber_Al's Avatar
    Join Date
    Dec 2004
    Location
    Wales
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    (off topic slightly) root priviliges?

    Quote Originally Posted by rbutler
    It means root@localhost doesn't have permissions to the database. I wouldn't use this account anyway. Go into your control panel and set up another user name and password. Never use the admin account for general access, you're exposing yourself and app to unnecessary security risks. Modify your connection string to account for you new username and password, if it was foo for username and cat for password then look below:
    Does root not have access to all databases by default when connecting from localhost?

    I thought it did or am I being stupid?

    Agree about the 'creation of a new account' ... is it a good idea to expressly apply the account to the specified database? What I mean is that I have a 'property' database and the only person I want to be able to access that is 'estates' user with password 'estates' .... not an anonymous localhost.

    (To shaabu ...: )Also, as a coding ideal, you should really have the connection vars as constants in a file and then include the constants file at the top of mydb.php so it would read as...

    Code:
    include("include/constants.php");
    ...mysql_connect($domain, $user, $pass) or die ....;

  5. #5
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Default mysql comes with user root and no pass, leave the password empty

  6. #6
    SitePoint Wizard rbutler's Avatar
    Join Date
    Jul 2003
    Location
    Springfield, MO
    Posts
    1,867
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Aber_Al
    Does root not have access to all databases by default when connecting from localhost?
    Probably, not a mysql person, more MS SQL Server

    Quote Originally Posted by Aber_Al
    Agree about the 'creation of a new account' ... is it a good idea to expressly apply the account to the specified database? What I mean is that I have a 'property' database and the only person I want to be able to access that is 'estates' user with password 'estates' .... not an anonymous localhost.
    Better than applying the root user name. Same thing as using sa in MS SQL server. You would have to be an idiot to let anonymous users access the database with that. By creating default accounts like this is that visitors visiting your page only have certain rights to the db in question. You wouldn't want joe smoe A being able to delete products from your products table inside your db. By setting a user with read only access on this database, you lock it down and avoid this situation.

    Unless I have misunderstood your issue.
    Ryan Butler

    Midwest Web Design

  7. #7
    SitePoint Member Aber_Al's Avatar
    Join Date
    Dec 2004
    Location
    Wales
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ah ha !

    Thanks, rbutler, hadn't thought about the two different users (visitor/admin) for the same database! Issue clarified cheers.

    </me goes to mysql command line>

    Cheers,

    Al.

  8. #8
    SitePoint Enthusiast pxlblitz's Avatar
    Join Date
    Jul 2004
    Location
    Bay City, MI
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have similar issues, that I need help understanding.
    I have set a password for my root user, and deleted all other users.

    At this point, I can connect to mysql using command line, logging in using root username & password. What I can't do is connect to the server using CocoaMySQL, using root username & password, and hostname.

    I went back to command line and queried to show everything for user =root, and my hostname is correct, password is encrypted, and it appears that all my privileges are set.

    Is there something I am missing, that won't allow me a connection using CocoaMySQL?
    Shawna ~~

  9. #9
    SitePoint Wizard rbutler's Avatar
    Join Date
    Jul 2003
    Location
    Springfield, MO
    Posts
    1,867
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Again, not really an open source guy (unless my job requires it ) but pxlblitz, your issue is probably the same. CocoaMySql is telling you that either root or your password isn't accessible via the database you have set up.

    Create yourself if you can figure out how, a different username and password on CocoaMySql that you can give permissions to. For example, username=foo, password=cat, give this combination to the database contained inside CocoaMySql.

    Other than that, can't be of much more help.
    Ryan Butler

    Midwest Web Design

  10. #10
    SitePoint Enthusiast pxlblitz's Avatar
    Join Date
    Jul 2004
    Location
    Bay City, MI
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    *endzone shuffle*

    got my problems all worked out! woOt! solution found here--->sourceforge/cocoamysql

    solution for other seekers
    Be sure that external access to your database is enabled (set % as Host in the tables mysql.user and mysql.db)

    and also:

    Logged into MySQL 4.1 from the terminal and ran GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY '' WITH GRANT OPTION;
    also after Granting privileges, be sure to
    mysq>FLUSH PRIVILEGES;
    Shawna ~~

  11. #11
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Regarding the CocoaMySQL issue

    pxlblitz (and rbutler),

    Here's a link to another sitepoint.com forum thread where I discuss my trouble, and solution, to getting CocoaMySQL to work under my configuration.
    Stuke
    Mac OS X (10.3.8) with Apache HTTP Server Version 1.3
    mysql-standard-4.1.10-apple-darwin7.7.0-powerpc
    Entropy-PHP-5.0.3-1


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •