Link to home
Start Free TrialLog in
Avatar of andrewharris
andrewharris

asked on

Warning: mysql_connect(): Access denied for user 'username'@'hostname.domain' (using password: YES)

I am trying to take over a PHP/MySQL system that someone else has done. I am setting up the web server and know that PHP works fine (example script works fine). However I get this error when PHP tries to conenct to the remote (on another server) MySQL Database. I can login without problem using the "username" login from the local machine.

Any Idea? I have NO CLUE when it comes to MySQL.

Andrew
Avatar of neester
neester
Flag of Australia image

Basically it means you are trying to connect to the MySQL database with teh wrong information.
Here is the function your using:

mysql_connect(HOST,USERNAME,PASSWORD);

the HOST is usually localhost.
the username is whatever you set it to, same with password.
eg:

$DB = mysql_connect('localhost','me','yeahright');


ALTHOUGH, some hosting resellers like to append your account name beofre the mysql login... eg:

my hosing does, so if i make a user called: databasemanager
then the actual login will be: neester_databasemanager

tryy that!
i just noticed you said a remote server.
you need to make sure that you are using the right IP for the "localhost" part...
since this will be the IP of the server your connecting to
i don't think it's a host problem neester. when the error message says 'Access denied', the server has probably received something.
you probably forgot to give privileges to your host using GRANT command on the mysql server :

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'myremotehost' IDENTIFIED BY 'mypassword';

see GRANT syntax for details : http://dev.mysql.com/doc/mysql/en/GRANT.html
Avatar of andrewharris
andrewharris

ASKER

psadac, I thought I had tried that but I did it again and got "Query OK, 0 rows affected (0.06 sec)" tried the site again but got exactly the same.

Just to give some more info. I own the server that has mysql on it. MySQL is version 4.1.8. In MySQL Administrator I can see my user "website" and if I click on that I have 2 options below it, localhost and 192.168.1.248.

The unedited error message is Warning: mysql_connect(): Access denied for user 'website'@'192.168.1.248' (using password: YES)

Andrew
Okey Dokey...well can you believe it it had to do with the password. I had hashes and dollars in my password. Not sure which one yet, but it didnt like one of them. I changed the password to something simple and now it works

Andrew
lol.
ok great :)
well thats an anwer that i dont think anyone could have given you!
:D
Is tehre anywhere I can log that as a bug? I am a little new to the MySQL game.

Andrew
i am sure it wasn't a bug.
you probably had this:

$DB = mysql_connect("iphere","userhere","password$here#asdasd$asdasd");

and php thought that $here and $asadasd were variables...
It was slightly different so tell me if this is still not a bug (going off the top of my head so syntax may not be 100% but you get my drift)

$hostname = "192.168.1.248"
$username = "website"
$password = "password$here#asdasd$asdasd"

$DB = mysql_connect($hostname,$username,$password);

Andrew
ASKER CERTIFIED SOLUTION
Avatar of neester
neester
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hai,

Try this.
GRANT ALL PRIVILEGES ON *.* TO website@"%" IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO website@192.168.1.248 IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;

Bye
Ajai
ajai - we worked it out mate :)
lol. you rekon!:-D
Hope I've guided him to right direction....
Just get sick of having to open a new post when I answered the question myself and then the post gets removed and no one gets the benefit of my answer.

Basically if you answer yourself and ask for PAQ - refund, it is saved
>> Just get sick of having to open a new post when I answered the question myself and then the post gets removed and no one gets the benefit of my answer.

Wow this is an old thread, cant remember it anymore.
Thanks for the A.
Ha Ha. Yeah very old. Cheers

Andrew