![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
$server = "12.34.56.78"; $user = "my_username"; $pass = "my_password"; $dbh = mysql_connect($server, $user, $pass, false, MYSQL_CLIENT_COMPRESS); |
|
Access denied for user 'nobody'@'localhost' (using password: NO) |
|
I'm guessing that the problem is with the $server variable, but I'm not sure how it's supposed to be written. Is it supposed to be just the IP (which is what PHP.net shows), or http://12.34.56.78, or what? |
#3
| |||||
| |||||
|
|
I'm moving an account to a new server (both semi-managed, and I have root access to both). For now, I'm trying to keep the database |
|
I'm trying to connect to the server in PHP. Here's what I'm using: $server = "12.34.56.78"; $user = "my_username"; $pass = "my_password"; |
|
$dbh = mysql_connect($server, $user, $pass, false, MYSQL_CLIENT_COMPRESS); On the old server, this worked correctly if I used $server = "localhost", and I didn't have "false, MYSQL_CLIENT_COMPRESS" when |
|
But when I do it this way, I'm getting the following error: Access denied for user 'nobody'@'localhost' (using password: NO) |
|
I'm guessing that the problem is with the $server variable, but I'm not sure how it's supposed to be written. Is it supposed to be |
#4
| |||
| |||
|
|
The IP address is supposed to be just an IP address, or a host name resolvable in DNS. No slashes or colons. MySQL does not use the http protocol. |
#5
| ||||||||
| ||||||||
|
|
I have an include file with just this sort of stuff in it, plus a database name. It avoids scattering login credentials all over multiple scripts, and it's easier when passwords get changed or the code gets moved to a different PHP server. |
|
Is $server set to an IP address other than "127.0.0.1" or "localhost"? Is $user equal to "nobody"? Is $pass an empty string or null? It would seem that you are attempting connection to the *WRONG SERVER*, possibly because PHP will automatically connect with defaults if you start running queries before opening a connection. If it says "using password: NO" and you think you supplied a password (not '' or null), this also suggests that it's not your call to mysql_connect that's getting the error. |
|
Does the error message give a file name and line number? Is that the file name and line number where you call to mysql_connect() is? |
|
Do you run any database queries *BEFORE* the call to mysql_connect()? Don't. Or is there another left-over call to mysql_connect()? Move the call to mysql_connect() earlier if needed. |
|
Change (temporarily) your call from mysql_connect() to mysql_fail() (Hint: there is no such function. Trying to run it will provoke an error message about an undefined function.) and see if you still get the same error message. |
|
The IP address is supposed to be just an IP address, or a host name resolvable in DNS. No slashes or colons. MySQL does not use the http protocol. |
|
The fact that you got an "Access denied" error indicates that you successfully connected to *some* server, possibly the wrong one. |
|
Can you temporarily shut down the server you don't think you are using? If you do, does the error message change to one of not being able to connect? |
#6
| |||
| |||
|
|
Jason C <jwca... (AT) gmail (DOT) com> wrote: $server = "12.34.56.78"; $user = "my_username"; $pass = "my_password"; $dbh = mysql_connect($server, $user, $pass, false, MYSQL_CLIENT_COMPRESS); If this is the code, then this Access denied for user 'nobody'@'localhost' (using password: NO) cannot be the error message. This login attempt used a locally running MySQL server and no password. Check your code. |
#7
| |||
| |||
|
|
If you do have root access to the machines, you better test the connection with the 'mysql' client tool. On the machine where PHP is running, try mysql -h 12.34.56.78 -u my_username -p If this works, then PHP shall work too. |
#8
| |||
| |||
|
|
On Wednesday, October 5, 2011 2:45:29 AM UTC-4, Axel Schwenke wrote: mysql -h 12.34.56.78 -u my_username -p If this works, then PHP shall work too. Using this, I get the following error: ERROR 1130 (HY000): Host '12.34.56.78' is not allowed to connect to this MySQL server How do I give the new server permission? |
#9
| |||
| |||
|
|
Only if the test connection works, it makes sense to test with PHP again. |
#10
| |||
| |||
|
|
Well, apparently I have something turned off to prevent PHP errors from showing on the screen; all I get was a "server error 500" page. |
|
I DID discover that if I turn off the firewall on the server with the database (using ConfigServer Firewall, aka CSF), then I get the |
![]() |
| Thread Tools | |
| Display Modes | |
| |