Connecting Tech Pros Worldwide Forums | Help | Site Map

Remote MySQL Server

Jerim
Guest
 
Posts: n/a
#1: Aug 14 '07
I have a script on one server, trying to access the MySQL database on
another server. The server with the script is on an outside network,
hosted with another company. The MySQL server is here in the
office;behind a firewall. Script works fine when it is on the local
machine, but when I moved it to the offsite webserver it gives me:

Warning: mysql_connect() [function.mysql-connect]: Lost connection to
MySQL server during query in /directory/directory2/functions/
shared_data_connections.php on line 29
Unable to connect to database.

The script is:

$username = "user";
$password = "password";
$hostname = "ip_address";
$database = "database";

$connection = mysql_connect($hostname, $username, $password)
or die ("Unable to connect to database.");
$open = mysql_select_db($database, $connection)
or die ("Unable to select database.".mysql_error());
return $connection;

One obvious problem could be the firewall. But since making any
adjustments to the firewall is frowned upon around here, I want to
cover some other bases first. Want to get some evidence that it
probably isn't something else. Any other ideas? I am very certain that
the user/pass are correct and that is the correct IP address. I have
also made certain that the user has access from any host.


Jerim
Guest
 
Posts: n/a
#2: Aug 14 '07

re: Remote MySQL Server


Forgot to mention that the server with MySQL on it, the one inside the
office, uses SSH for connectivity.

burgermeister01@gmail.com
Guest
 
Posts: n/a
#3: Aug 14 '07

re: Remote MySQL Server


On Aug 14, 3:18 pm, Jerim <wyo...@gmail.comwrote:
Quote:
I have a script on one server, trying to access the MySQL database on
another server. The server with the script is on an outside network,
hosted with another company. The MySQL server is here in the
office;behind a firewall. Script works fine when it is on the local
machine, but when I moved it to the offsite webserver it gives me:
>
Warning: mysql_connect() [function.mysql-connect]: Lost connection to
MySQL server during query in /directory/directory2/functions/
shared_data_connections.php on line 29
Unable to connect to database.
>
The script is:
>
$username = "user";
$password = "password";
$hostname = "ip_address";
$database = "database";
>
$connection = mysql_connect($hostname, $username, $password)
or die ("Unable to connect to database.");
$open = mysql_select_db($database, $connection)
or die ("Unable to select database.".mysql_error());
return $connection;
>
One obvious problem could be the firewall. But since making any
adjustments to the firewall is frowned upon around here, I want to
cover some other bases first. Want to get some evidence that it
probably isn't something else. Any other ideas? I am very certain that
the user/pass are correct and that is the correct IP address. I have
also made certain that the user has access from any host.
My immediate thought, and this is more of a shot in the dark than
anything, but are you specifying the correct port number. It wouldn't
be an issue if you were on a local machine, but if you are connecting
to a remote host they might have MySQL running on a different port,
not to mention the SSH connection. If that doesn't help, I googled
this article which may be helpful:

http://blog.taragana.com/index.php/a...ing-query-fix/

Good luck!

Jerim
Guest
 
Posts: n/a
#4: Aug 14 '07

re: Remote MySQL Server


On Aug 14, 3:39 pm, burgermeiste...@gmail.com wrote:
Quote:
On Aug 14, 3:18 pm, Jerim <wyo...@gmail.comwrote:
>
>
>
Quote:
I have a script on one server, trying to access the MySQL database on
another server. The server with the script is on an outside network,
hosted with another company. The MySQL server is here in the
office;behind a firewall. Script works fine when it is on the local
machine, but when I moved it to the offsite webserver it gives me:
>
Quote:
Warning: mysql_connect() [function.mysql-connect]: Lost connection to
MySQL server during query in /directory/directory2/functions/
shared_data_connections.php on line 29
Unable to connect to database.
>
Quote:
The script is:
>
Quote:
$username = "user";
$password = "password";
$hostname = "ip_address";
$database = "database";
>
Quote:
$connection = mysql_connect($hostname, $username, $password)
or die ("Unable to connect to database.");
$open = mysql_select_db($database, $connection)
or die ("Unable to select database.".mysql_error());
return $connection;
>
Quote:
One obvious problem could be the firewall. But since making any
adjustments to the firewall is frowned upon around here, I want to
cover some other bases first. Want to get some evidence that it
probably isn't something else. Any other ideas? I am very certain that
the user/pass are correct and that is the correct IP address. I have
also made certain that the user has access from any host.
>
My immediate thought, and this is more of a shot in the dark than
anything, but are you specifying the correct port number. It wouldn't
be an issue if you were on a local machine, but if you are connecting
to a remote host they might have MySQL running on a different port,
not to mention the SSH connection. If that doesn't help, I googled
this article which may be helpful:
>
http://blog.taragana.com/index.php/a...sql-server-has...
>
Good luck!
I also found that when you setup MySQL, you can set it up to use
either TCP connections or shared memory. In this case, it is using
shared memory, so no TCP connection would ever work. I have found a
solution that works. Basically, I have an include file on the MySQL
server, that is used by the webpage on the remote server. All the SQL
code is in the include, which is local to the MySQL database.

C.
Guest
 
Posts: n/a
#5: Aug 15 '07

re: Remote MySQL Server


On 14 Aug, 22:38, Jerim <wyo...@gmail.comwrote:
Quote:
On Aug 14, 3:39 pm, burgermeiste...@gmail.com wrote:
Quote:
On Aug 14, 3:18 pm, Jerim <wyo...@gmail.comwrote:
>
Quote:
Quote:
I have a script on one server, trying to access the MySQL database on
another server. The server with the script is on an outside network,
hosted with another company. The MySQL server is here in the
office;behind a firewall. Script works fine when it is on the local
machine, but when I moved it to the offsite webserver it gives me:
>
Quote:
Quote:
Warning: mysql_connect() [function.mysql-connect]: Lost connection to
MySQL server during query in /directory/directory2/functions/
shared_data_connections.php on line 29
Unable to connect to database.
>
<snip>
Quote:
Quote:
Quote:
One obvious problem could be the firewall. But since making any
adjustments to the firewall is frowned upon around here,
! of course its frowned upon but you need to work out what the problem
is before you worry whether or not it needs to be changed.

Really this is not a PHP question - try using the MySQL command line
interface. The error suggests that PHP is able to conect to the server
but subsequently loses the connection - in which case its not simple
port blocking (AFAIK, unlike FTP, MySQL uses a single connection from
client to server).

I'd suggest you sit down with your local friendly network admin
(ignoring the oxymoron) the mysql cli tool and a copy of wireshark and
see if you can replicate the error.

C.

Closed Thread