Command-line PHP, can't connect to remote MySQL

edigest

Active Member
#1
Probably something basic I'm missing, but I'm unable to connect to a remote MySQL server from command-line PHP. Using Latest LSWS configured with suPHP.

Running

#php test_mysql.php

<?php
$username = "myuser";
$password = "123456";
$hostname = "my.remotesql.com";


$link = mysql_connect($hostname, $username, $password);

if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>


Returns this error:

Warning: mysql_connect(): Access denied for user 'myuser'@'hostname.com' (using password: YES)

The error references the server hostname where the script is run rather than the remote sql host in $hostname.

I tried adding mysql.default_host to php.ini -- no help. Also, granted permissions on the sql server.

FWIW, I am trying to make MailWatch work with a remote db server. MailWatch runs as root outside of web space.
 

edigest

Active Member
#3
Yes, the remote server works normally with regular users (websites) and connecting from the command-line works normally.

The only thing I can't make work is connecting from php-cli:

#php test_mysql.php
 

edigest

Active Member
#5
Same result ...

The description of the function is as follows:

resourcemysql_connect ([ string $server = ini_get("mysql.default_host") [, string $username = ini_get("mysql.default_user") [, string $password = ini_get("mysql.default_password") [, bool$new_link = false [, int $client_flags = 0 ]]]]] )

I tried ini_set() to change the default host and it still attempts to connect to hostname rather than remote host.

Has to be something in the behavior of suPHP -- I just can't find it.
 

NiteWave

Administrator
#6
there should be ok with suPHP or not -- when you run in command line, you run as root, no privilege problem.

I think there is no trick -- please forcus on the error message:
Warning: mysql_connect(): Access denied for user 'myuser'@'hostname.com' (using password: YES)
while I'm writing, I found
#mysql -h hostname.com -u myuser -p
should be
#mysql -h my.remotesql.com -u myuser -p

if this command succeeds, test_mysql.php should work as well.
 
Top