You may also look at SSH port forwarding, this allows you to create an
encrypted tunnel between the two machines, then you connect to the local
port, the data gets encrypted sent across the wire and decrypted at the

Look at -L in your ssh man or search google for ssh tunneling

stunnel is nice because you don't have to leave an ssh connection open.

NELREMOTELY for more info on configuring stunnel, the reference is for
PostgreSQL but the stunnel part is not db dependant.


-----Original Message-----
From: Stefen Lars [mailto:[EMAIL PROTECTED]]
Sent: Monday, April 29, 2002 9:24 AM
Subject: [PHP] Secure MySQL connections in PHP with 'stunnel'

Hello all

I have written a very simple PHP script to copy the data from one MySQL 
database table on SERVERA to another MySQL database table on SERVERB.

Using PHP, I simply connect to each server and copy the data across. That 
works well.

However, natively, MySQL works with clear text. i.e. the data is copied 
across the Internet in clear text (a bad thing).

I would now like encrypt the MySQL data between SERVERA and SERVERB.

After searching with Google, I see that stunnel is a tool to use.

However, I have been trying with no avail to create an encrypted connection 
between the two servers from MySQL to work.

Following the instructions at:

I have come up with the following:

SERVERA (master)
/usr/local/sbin/stunnel -f -P/tmp/ -c -d 3308 -r SERVERA:3307
/usr/local/sbin/stunnel -f -P/tmp/ -p /usr/local/ssl/certs/stunnel.pem -d 
3307 -r 3306

SERVERB (slave)
/usr/local/sbin/stunnel -f -P/tmp/ -c -d 3308 -r SERVERB:3307
/usr/local/sbin/stunnel -f -P/tmp/ -p /usr/local/ssl/certs/stunnel.pem -d 
3307 -r 3306

This does not work. When I connect to the slave with:


$db_link = mysql_connect(SERVERB:3308, "User", "Pwd")
        or die("Cannot connect to db");

        or die("Cannot select MASTER db\n");


and select / insert data into SERVERB, the data is selected / inserted to 
the database on SERVERA. This is very strange.

Has anyone else tried using stunnel to achieve what I want to do? If so, I 
would REALLY like to hear how you achieve the encrypted link.

Or are there other ways of securely coping data from one MySQL server to 

Using stunnel seems rather fiddly...

Any comments on this subject will be well received.


Chat with friends online, try MSN Messenger:

PHP General Mailing List (
To unsubscribe, visit:

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to