Remote MySQL Connection Problem 
Author Message
 Remote MySQL Connection Problem

Hello,

I'm having quite a problem getting a set of PHP scripts to talk to a remote
MySQL server.  The scripts are for an image gallery which I've been using
for a while.  I need to move the MySQL data to another box as the web server
is far too slow now to handle all of the images stored in the database.

The web server runs RedHat 6.2 on a sparc machine.  I had to compile &
install Apache, PHP, & MySQL by hand - so perhaps I fouled something up
during that process which prevents me from talking to remote MySQL servers.
The scripts have no problem querying the MySQL server on the local machine -
but when I modify them to query the remote machine the script dies with
"Could not select database".

Web server = 192.168.1.3
MySQL Server = 192.168.1.2

Same physical LAN, no firewalls between them.  I've inserted the appropriate
user rights on the remote MySQL server.

FWIW, I don't see any errors on the remote machine (in the mysql error log).

Here are the scripts.  Any ideas appreciated!

(I call gal.inc.php as an include in my main page)

===================
gal.inc.php
===================

<?PHP
include "db_connect_inc.php";
 $result=MYSQL_QUERY("SELECT * FROM gallery");
 while ($line = mysql_fetch_array($result))
 {
  extract($line);
?>
<p><a href="showgallery.php?galleryname=<? echo "$gallery"; ?>&galleryid=<?
echo "$id"; ?>&gallerydesc=<? echo "$description"; ?>" class=\"links\">
<?echo "$gallery";?>
</a><br>
<?PHP
  echo "$description<br><br>";
 }
?>

===================

db_connect_inc.php
===================

<?
 include "./admin/config.inc.php";
 $dblink = mysql_connect($hostname, $usernamedb, $passworddb)or die ("Could
not connect");
 mysql_select_db ($dbName) or die ("Could not select database");
?>

===================

./admin/config.inc.php
===================

<?
$hostname = "192.168.1.2";  // database hostname
$usernamedb = "gallery";  // database username
$passworddb = "pictures";  // database password
$dbName = "album";  // database name
$rootweb = " http://www.*-*-*.com/ ;; // root web for main
script
?>

(note - I've also tried adding the MySQL port number (3306) to
./admin/config.inc.php, but that made no difference)



Tue, 17 May 2005 01:57:54 GMT  
 Remote MySQL Connection Problem


Quote:
> Hello,

> I'm having quite a problem getting a set of PHP scripts to talk to a
remote
> MySQL server.  The scripts are for an image gallery which I've been using
> for a while.  I need to move the MySQL data to another box as the web
server
> is far too slow now to handle all of the images stored in the database.

> The web server runs RedHat 6.2 on a sparc machine.  I had to compile &
> install Apache, PHP, & MySQL by hand - so perhaps I fouled something up
> during that process which prevents me from talking to remote MySQL
servers.
> The scripts have no problem querying the MySQL server on the local
machine -
> but when I modify them to query the remote machine the script dies with
> "Could not select database".

> Web server = 192.168.1.3
> MySQL Server = 192.168.1.2

> Same physical LAN, no firewalls between them.  I've inserted the
appropriate
> user rights on the remote MySQL server.

> FWIW, I don't see any errors on the remote machine (in the mysql error
log).

> Here are the scripts.  Any ideas appreciated!

> (I call gal.inc.php as an include in my main page)

> ===================
> gal.inc.php
> ===================

> <?PHP
> include "db_connect_inc.php";
>  $result=MYSQL_QUERY("SELECT * FROM gallery");
>  while ($line = mysql_fetch_array($result))
>  {
>   extract($line);
> ?>
> <p><a href="showgallery.php?galleryname=<? echo "$gallery";
?>&galleryid=<?
> echo "$id"; ?>&gallerydesc=<? echo "$description"; ?>" class=\"links\">
> <?echo "$gallery";?>
> </a><br>
> <?PHP
>   echo "$description<br><br>";
>  }
> ?>

> ===================

> db_connect_inc.php
> ===================

> <?
>  include "./admin/config.inc.php";
>  $dblink = mysql_connect($hostname, $usernamedb, $passworddb)or die
("Could
> not connect");
>  mysql_select_db ($dbName) or die ("Could not select database");
> ?>

> ===================

> ./admin/config.inc.php
> ===================

> <?
> $hostname = "192.168.1.2";  // database hostname
> $usernamedb = "gallery";  // database username
> $passworddb = "pictures";  // database password
> $dbName = "album";  // database name
> $rootweb = "http://www.blahblahblahblah.com/gallery"; // root web for main
> script
> ?>

> (note - I've also tried adding the MySQL port number (3306) to
> ./admin/config.inc.php, but that made no difference)

Also - the remote server is running MySQL version 3.23.53a on RedHat 8.  The
local server runs MySQL version 3.23.53 (RedHat 6.2, precompiled version for
sparc).


Tue, 17 May 2005 02:01:46 GMT  
 Remote MySQL Connection Problem


Quote:

> I'm having quite a problem getting a set of PHP scripts to talk to a remote
> MySQL server.  

> The scripts have no problem querying the MySQL server on the local machine -
> but when I modify them to query the remote machine the script dies with
> "Could not select database".

This means that the scripts are able to connect to the server.  So your
problem is most likely in the permissions.  Log into MySQL as root user
and run these commands:

USE mysql;
SELECT Host, User, Select_priv, Insert_priv FROM db WHERE Db='album';
SELECT Host, Select_priv, Insert_priv FROM user WHERE user='gallery';

The first command will take you into the MySQL system database. The
second command will show you which users connecting from which hosts
are allowed to connect to the database "album" and whether they have
select and insert privileges on that database.  The last command will
tell you whether the user "gallery" exists, from which hosts it is
allowed to connect, and whether it has select and insert privileges
on your server.  

In order for your setup to work, the following must be true:

1. User "gallery" exists and is allowed to connect from 192.168.1.3
   or from anywhere (MySQL will denote it with a "%" sign).
2. Database "album" is accessible to user "gallery" when that user
   connects from 192.168.1.3 or from anywhere.

Since you can't connect now, it means that one (or both) of the above
does not hold (my bet is on the second).  If you need further help,
you'll have to post the outputs of the last two MySQL commands.

Cheers,
NC



Tue, 17 May 2005 13:08:21 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Connection to remote server with MySQL under Win/2K

2. Help needed - mySQL connection problem

3. MySQL connection problem with linux

4. Running application remote, how many kbs ADSL-connection?

5. Remote connection of sites

6. Remote Connection (Cross Post)

7. Remote Connections

8. Remote panel connection broken only when VI running

9. How can I disable remote access connection window ?

10. "Connection closed by remote server"

11. Remote db connections possible with DCOracle2?

12. Remote DB connection with tclodbc

 

 
Powered by phpBB® Forum Software