Can't connect to DB server: Access denied for user ''@'localhost' (using password: NO)
Hi,
We have an inhouse MySQL database that is only accessible inhouse - you cannot access it remotely. There is no user/password required to access this database - you simply go to the IP address in your browser and everything is there.
We would like to move it online so we can access it remotely from anywhere.
I set up a cPanel account and imported this database so it's accessible via a domain name. When I go to the domain name in my browser, here is exactly what shows on my browser screen:
Could not connect to DB server:Access denied for user ''@'localhost' (using password: NO)
Access denied for user ''@'localhost' (using password: NO)
Here are the first few lines of the config.php file:
= "cpanelusername_databasename";
$config["user"> = "cpanelusername_databaseusername";
$config["password"> = "databasepassword";
$config["host"> = "localhost";
$config['baseurl'> = ", $config["user">, $config["password">);
$sqlnames = "SET NAMES utf8;";
mysql_query($sqlnames);
if(!$db) echo "
Could not connect to DB server:" . mysql_error() . "
\n"; mysql_select_db($config["db">, $db) or die (mysql_error()); $config['site_db'>=$db; ?> Is there anything here that is incorrect? I can't find any other files that would connect the database to the webserver. Thank you in advance for your assistance.-
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 -
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
- Have a Database and an User assigned to it.
- Allow your local computer's IP in cPanel's Remote MySQL tool
0 -
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 -
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 @ffeingol0 -
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 -
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 -
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
Thank you for posting this - this is very good to know.0 -
Good to hear that it is resolved. :) 0 -
Glad it's all set! 0
Please sign in to leave a comment.
Comments
9 comments