473,395 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Remote MySQL Server

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.

Aug 14 '07 #1
4 3878
Forgot to mention that the server with MySQL on it, the one inside the
office, uses SSH for connectivity.

Aug 14 '07 #2
On Aug 14, 3:18 pm, Jerim <wyo...@gmail.comwrote:
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!

Aug 14 '07 #3
On Aug 14, 3:39 pm, burgermeiste...@gmail.com wrote:
On Aug 14, 3:18 pm, Jerim <wyo...@gmail.comwrote:
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...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.

Aug 14 '07 #4
C.
On 14 Aug, 22:38, Jerim <wyo...@gmail.comwrote:
On Aug 14, 3:39 pm, burgermeiste...@gmail.com wrote:
On Aug 14, 3:18 pm, Jerim <wyo...@gmail.comwrote:
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.
<snip>
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.

Aug 15 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: hera | last post by:
I am new at php and MySQL and have some (ugly, I'm sure) code to populate form select fields with data from a MySQL database, so a user can use those to sort/filter and view the 3,000 records. No...
3
by: JStrummer | last post by:
I have a mySQL database located on a remote host's server. I would like to schedule a task on my local Windows computer to retrieve a backup/dump of this remote database. I have contacted my...
4
by: Ian Davies | last post by:
Hello all The following code allows me to connect to a local MySQL database on my pc from a VB6 project. **************************************************************************** ** Dim...
7
by: Ike | last post by:
Let's say I have a MySQL 4.12 database, opened to the internet on 111.111.111.111 allowing all incoming and outgoing ports. I have a username and password setup, which CAN connect to this database,...
4
by: courtney.machi | last post by:
Hello, I am trying to connect to a remote mysql server through php. Here's the code: mysql_connect("my.hostname.edu", "username", "password") or die (mysql_error());...
2
by: Martin | last post by:
Hi all. I have a fully functional page hosted on my PC that uses PHP and connects to MySQL on my PC to generate it's code. I now have some web hosting available which includes both PHP and...
2
by: dronkanoki | last post by:
I am attempting to set up myODBC 3.51 on Win XP Pro to a remote MySQL Linux server. I get the following error: Access denied for user: 'username@ipaddress.serviceprovider.net' (Using password:...
1
by: mcyi2mr3 | last post by:
hi all how do i make a command line connection to a remote mysql server? for local connections i know it is: mysql -u root dbname how do i connect to a remote server with a password? thanks...
4
by: Pseudonyme | last post by:
A Paris Le 14 Nv MMVII Dear Madam and Sir, Do you know how to access a MYSQL DB from an external server ? We read the information and studied :
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.