Link to home
Start Free TrialLog in
Avatar of Eqbal
Eqbal

asked on

PHP script can't connect to MySQL server

I configured my server and allowed my IP to connect remotely.

I entered IP of the server, username and password of mysql user in SQLyog (a GUI for managing mysql server). It connects successfully to database and I can manage everything.

I also have a PHP script to connect to the database. the code is something like this:
 mysql_connect('xx.xx.xx.xx', 'mysql_user', 'pass') or dir(mysql_error());

Open in new window


It displays this error:
Access denied for user 'mysql_user'@'yy.yy.yy.yy' (using password: YES) in /home/.../mysql.inc.php  on line 9

Open in new window


Why Sqlyog can connect and PHP script can't?
I think it's because 'yy.yy.yy.yy' in username. but I can't force PHP not to use it.
Avatar of shobinsun
shobinsun
Flag of India image

Hi,

The username or password is not correct.

Please double check again.

check in the command line:

mysql -u username -p password
Avatar of Eqbal
Eqbal

ASKER

username/password in sqlyog and script is same. sqlyog works. php doesn't work.
ASKER CERTIFIED SOLUTION
Avatar of Beverley Portlock
Beverley Portlock
Flag of United Kingdom of Great Britain and Northern Ireland 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
If you're uploading the script to your server, then you don't need to connect to it using an IP Address. You use LOCALHOST. The script can access the server as localhost when it's on the same server.



mysql_connect('localhost', 'mysql_user', 'pass') or dir(mysql_error());

Open in new window

Please double check your database password, user and also the privilege assigned to the user for the DB you are connection.

Hope this helps
Addy
Avatar of Eqbal

ASKER

@bportlock

Thank you for response. I run these commands:

GRANT ALL PRIVILEGES ON *.* TO 'mysql_user'@'yy.yy.yy.yy' IDENTIFIED BY '********';FLUSH PRIVILEGES;
The first Command displays: Query OK, 0 rows affected (0.00 sec)

Now, The script can connect very good. but at first query it displays that error again:

Access denied for user 'mysql_user'@'yy.yy.yy.yy' (using  password: YES)

The script works fine with local mysql server.

Can you help me?
Avatar of Eqbal

ASKER

I raised point value.
can u please post the code you are using?

Thanks
Addy
You need to have root privilege to grant access. at present its not there
Avatar of Eqbal

ASKER

@AddyWatson:
The script is so big. Which section do you want to see?

@shinuq:
Yes. I used "mysql -uroot -p".
SOLUTION
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
mainly DB Connection portion.

Thanks
Addy