Skip to main content

Can't connect to DB server: Access denied for user ''@'localhost' (using password: NO)

Comments

9 comments

  • cPRex Jurassic Moderator
    Hey there! I don't claim to be a PHP wizard, but I've looked at many connection strings and that seems fine to me. I'd start by eliminating that from the equation completely and test the user access on the command line with this: mysql -u username -p
    That will prompt you for the password for that user you've created. If that works, it's something with the site's code or connection. If that doesn't work, the issue is with the access for the user to the database. You can make sure the user has full access to the database through the cPanel >> MySQL Database area near the bottom of the page by just trying to re-grant access. It won't hut anything to re-save the values on that page.
    0
  • keat63
    When you created the database on your cpanel, did you then create a user and assign access rights to that database. And grant all privileges. Is the software which access the database hosted on the same server, or is this on a local PC. I found this. To connect from a script in your cPanel account to a database also in your cPanel account you need to just
    • Create Database
    • Create User for it
    • Give necessary grants to the User
    To connect locally, from your own computer to a cPanel hosted database you need to:
    • Have a Database and an User assigned to it.
    • Allow your local computer's IP in cPanel's Remote MySQL tool
    The latter part might be tricky, if you have many remote users, or dynamically assigned IP's
    0
  • ffeingol
    The error messages is "interesting" [QUOTE] ''@'localhost' (using password: NO)
    Based on that error, it's not getting a username (it's '' which it should be 'something') and it is showing that no password was provided. Are you sure that your config file is getting properly included? Path's on to the included files may be very different than what you had on your local server.
    0
  • kodeslogic
    If you're able to login to MySQL from the command prompt by mysql -u username -p
    , here the username and password must be the same as in your database config file. Next step you should check that - in the cPanel interface make sure you have a database and database user and they are correctly mapped with required privileges - the database config file is correctly included for your website code as suggested by @ffeingol
    0
  • cPRex Jurassic Moderator
    I can never tell if the empty quotes are an error or if they removed that data because it's posted on the forum, but good call, @ffeingol !
    0
  • ctrlaltdel21
    The error messages is "interesting" Based on that error, it's not getting a username (it's '' which it should be 'something') and it is showing that no password was provided. Are you sure that your config file is getting properly included? Path's on to the included files may be very different than what you had on your local server.

    I wondered the exact same thing because whenever I found this error online by others having the same issue, they all had a username where I had the " only. Oddly, after reading @cPRex 's response, I reset my password on the database, the error disappeared and our site displayed. Based on the error I was receiving, it doesn't make sense to me that's all it was because the error didn't show my username and said I wasn't using a password. Very strange. Thank you for your response.
    0
  • ctrlaltdel21
    To connect locally, from your own computer to a cPanel hosted database you need to:
    • Have a Database and an User assigned to it.
    • Allow your local computer's IP in cPanel's Remote MySQL tool
    The latter part might be tricky, if you have many remote users, or dynamically assigned IP's

    Thank you for posting this - this is very good to know.
    0
  • kodeslogic
    Good to hear that it is resolved. :)
    0
  • cPRex Jurassic Moderator
    Glad it's all set!
    0

Please sign in to leave a comment.