1

I have recently started exploring free hosting sites where they provide free mysql and php.

I have created a database and trying to connect to the database from php script. But while running the php. I am getting following error :

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'a1696486_test '@'localhost' (using password: YES) in /home/a1696486/public_html/myphp/test1.php on line 2

Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'a1696486'@'localhost' (using password: NO) in /home/a1696486/public_html/myphp/test1.php on line 3

Any idea whats the problem ?

Regards, Shankar

2
  • 2
    Wrong user or password? Can you show the code you use to connect? why are there 2 different users? Commented Jul 22, 2011 at 10:33
  • try root user. if works then problem in creating user or granted roles Commented Jul 22, 2011 at 10:35

1 Answer 1

2

I have this issue on our dedicated servers, and the solution for me is to provide the fully qualified domain name rather than 'localhost'. For exmaple, my connection is:

mysqli_connect('dedi81.jnb1.host-h.net', 'user', 'pass', 'db');

Where even though localhost is the same as dedi81.jnb1.host-h.net (MySQL server and web server on one machine) I - for some reason - cannot use 'localhost'.

Another issue may be that on the hosting company you're with, they have not granted to you the correct permissions, or that there is indeed an error with the username and / or password.

You can also try and substitute 'localhost' with the IP address of the MySQL machine.

Kind regards, Simon

Sign up to request clarification or add additional context in comments.

2 Comments

The host should be right, as he can connect. It's the user who's either wrong or without the sufficient privileges.
@Damien Pirsy - Good observation, you're correct. Silly me for not seeing that, and based on your comment, it can only be an incorrect username or password, or that the user has no permissions granted to him.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.