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:
It displays this error:
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.
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());
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
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.
ASKER
username/password in sqlyog and script is same. sqlyog works. php doesn't work.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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());
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
Hope this helps
Addy
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?
Thank you for response. I run these commands:
GRANT ALL PRIVILEGES ON *.* TO 'mysql_user'@'yy.yy.yy.yy'
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'
The script works fine with local mysql server.
Can you help me?
ASKER
I raised point value.
can u please post the code you are using?
Thanks
Addy
Thanks
Addy
You need to have root privilege to grant access. at present its not there
ASKER
@AddyWatson:
The script is so big. Which section do you want to see?
@shinuq:
Yes. I used "mysql -uroot -p".
The script is so big. Which section do you want to see?
@shinuq:
Yes. I used "mysql -uroot -p".
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
mainly DB Connection portion.
Thanks
Addy
Thanks
Addy
The username or password is not correct.
Please double check again.
check in the command line:
mysql -u username -p password