dash34

Registered
Apr 19, 2013
2
0
1
cPanel Access Level
Website Owner
Hopefully this has an obvious answer - sorry if this is a stupid noob question. I read through as many threads as possible on the forum before posting this.

I have a user that I have added to my database in cPanel (yup, definitely added, not just created, all privileges were granted as well just to be sure). I have reset the password a couple of times to make sure the password was correct.

My php script tries to connect to the database but gets the access denied error. My script prints out the error:

Could not connect: Access denied for user 'dash34_test'@'localhost' (using password: YES)

This database was created in cPanel. The database schema was imported from a .sql file through phpmyAdmin from the mySQL instance on my home computer - the mySQL version on my computer is 5.5.27. I checked the .sql file and there is NO MENTION of the database name anywhere except in a comment at the top of the file. The import process just creates tables - it doesn't affect the database name or users at all.

Here is the script I am using to connect:

$db = mysql_connect("localhost","dash34_test","xxxxxxxx"); // note that I have overtyped the real password with xxxxxxxx
if (!$db)
{
die('Could not connect: ' . mysql_error());
}

So, there is a database to connect to, the user exists for this database and has the correct password. The script has the correct user name and password.

What should I try next?

thanks in advance for any help.
 
Last edited:

arunsv84

Well-Known Member
Oct 20, 2008
372
1
68
127.0.0.1
cPanel Access Level
Root Administrator
$db = mysql_connect("localhost","dash34_test","xxxxxxxx"); // note that I have overtyped the real password with xxxxxxxx
if (!$db)
{
die('Could not connect: ' . mysql_error());
}
Just to confirm, I cant see database name in the above script. :confused:

If you have already mentioned the database name in script, and just skipped it here, you need to contact your hosting provider.

Just request them to grant privileges from backend/shell. You need to provide them database username, password and database name

Cheers!!!
 

dash34

Registered
Apr 19, 2013
2
0
1
cPanel Access Level
Website Owner
Database name isn't given at this stage. mysql_connect just establishes a connection to the host. Selecting a database is usually the next step.

I noted that I can connect to and access the database from my php code using my cPanel username and password. Definitely not a good idea to have that password sitting in the php code though.

Still mystified about why the user I created isn't allowed to connect. Is this a cPanel error or a mySQL problem?

I tried to look at the users in the information schema. I noted that in the USER_PRIVILEGES table there is no entry for the dash34_test user. Did cPanel not store the username and privileges there? If not, where did it put it?