Strange Php MySQLconnection error

Hello,

We have a couple of servers, I am able to connect via a Php generated Web page to MySQL on server 1 Ok.
Using code:

$dbcnx1 = @mysql_connect(‘server1.anoox.com’, ‘root’, ‘xyz9090’);
if (!$dbcnx) {
exit (‘<p> Unable to connect to the db on server 1 at this time.’);
}

But when I try to connect to MySQL on our other servers, I get Error message!
here is the other connection:

$dbcnx4 = @mysql_connect(‘server4.anoox.com’, ‘root’, ‘yzyzyz0099’);
if (!$dbcnx4) {
exit (‘<p> Unable to connect to S4 Database at this time, please try later.’);
}

What is going on!
What do I need to do to connect to MySQL on server4?

Regards,

Do the other servers support external connections?
Does the same user have privileges on the other servers?
What’s the MySQL error that’s being kicked back?

if(!$dbcnx) { 
 die("<p>Failed to connect to the database: " . mysql_error() . "</p>");
}

Hi,

1st, Thanks for your response.
In answer to your questions:

1- How do I determine if MySQL on other server or on this server accepts external connection?
Of course on other servers, yes, since I am connecting to their MySQLs via other servers.
But to this server4, this is 1st time I am trying connection to its MySQL via another server.

2- I am not sure what you mean.
I am logging as root onto this MySQL DB.

3- And here is the Error message that this MySQL kicks back:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user ‘root’@‘server3.anoox.com’ (using password: YES) in /var/www/html/anoox.com/misc/me_via_s4.php on line 5

FYI:
1- The address to this server is server4.anoox.com, so that server3.anoox.com is a legacy thing.
2- I did even try server3.anoox.com as the path for the mysql_connect to this server but it
generated same error.

ThanX,

Based on the error message, it seems that the servers support external connections. Most likely, the connection would be blocked on a firewall but all seems to be okay here.

Are there different databases on each server, or is it a mirrored database? If they are different databases, which I suspect is the case, you may have different root passwords for each database server. The error message you provided indicates that the user (root) does not have sufficient permission to access the database. Even if you believe the same user is configured on each database, I would recommend resetting the password to the root user on the other databases to double check that it’s synchronized.

On another security note, it’s generally not a good idea to use root for any application purpose. Better to create another user with more limited privileges just in-case that user account falls into the wrong hands. steps off soap box

Yes. This is a good point which I intend to get into ASAP I am done with this urgent issue of needing to access the MySQL DB on server4 via Php.

Regards,
Dean

SSH to server4. bring up the mysql prompt as root.

USE mysql
SELECT User,Host FROM user WHERE User = ‘root’ ORDER BY User

You’re looking for an entry that either has your connecting machine’s IP, or %, as the Host.

If that exists, you’ve given an incorrect password.

Hi,

I did what you listed below.
And there is an entry that has %, as the Host.
So what to do now to correct the problem?
That is be able to remotely connect to this MySQL server via Php on another server?

Regardsm

My next step would be to add Password to the retrieved fields on that query, and make sure the localhost password is the same as the one for %. The error you’re reporting indicates that the system denied your access based on password.

QUOTE=StarLion;4959681]My next step would be to add Password to the retrieved fields on that query,

Not sure what you mean by this!
I mean these entries in the mysql.user Table of course have password already.

and make sure the localhost password is the same as the one for %.

I do not want to change existing passwords, since there are many programs in JSP and Php
that are connecting to this DB and do not want them to start failing.

So how about we add a new entry to this mysql.user table, which entry has as host the IP of the server
from which server I want to remotely connect to this servers MySQL?

Regards,

Well the point of looking to see if the localhost and % password were the same is that you may have the wrong password in your file (if the localhost password is abc123, then when you SSH in, you’ll use that password. But if the % password is 123abc, telling your script to connect to the server with abc123 wont work.)

You can add another user entry for the specific IP if you want, i’m not the one running your server :stuck_out_tongue:

This is exactly why you should be using different users, with appropriate permissions, for different applications.

Well I added a new root user to mysql/user Table for the IP of the server that I am trying to remotely to connect this MySQL sever,
but same error! Will not allow connection.

Ayayayayay :frowning:

Shouldn’t the IP address be of the host server, not the one that’s attempting to make the connection? So if the MySQL server is hosted on 1.1.1.1 and the server 2.2.2.2 is trying to connect to it, the IP address in the user table on 1.1.1.1 should be 1.1.1.1.

Uh no, it should be 2.2.2.2. Because when 2.2.2.2 connects to it, thats what the “Host” of the connecting party is.

Right. I’m starting to confuse myself now so respectfully bowing out here. :smiley:

Yes, Exactly.
I read his message couple of times because I could not believe what I was reading.
So yes exactly, if server 2 is connecting to server 4, the HOST IP on user table of server 4 needs to be that of S2.
Well what the HEK. I have added this entry into the user table and it is still not connecting!
That is I still get error message:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user ‘root’@‘server3.anoox.com’ (using password: YES) in /var/www/html/anoox.com/misc/me_via_s4.php on line 5
connection via server4.anoox.com tried and failed

EVEN though I have now added the HOST ip of the connecting server into the mysql.user Table of the server that I am connecting to and I am using this just created new password as the password for connecting.

Ayayayay :frowning:

So you added a new user on server4… and it still denied you. Hm… Okay, at this point i’m tapped out of ideas too… gonna flag this for moving to mySQL and try and get someone else to answer it.

Status 1045, Cause Unknown.

Yes, exactly.
I guess in hindsight I should have posted this to MySQL.
ThanX.