connecting to MySQL database thru SSH tunnel

118 views
Skip to first unread message

Sieg Lindstrom

unread,
Dec 7, 2011, 5:08:53 PM12/7/11
to use-li...@lists.runrev.com
I have an app for managing data in a MySQL database on a remote server. It¹s
worked fine for years but now I would like to route the connection thru an
SSH tunnel. It uses a port number other than 3306 (PortNumberHere in the
function example below). So I¹ve changed the relevant function from this...

put
revOpenDatabase("MySQL","madeuphost.com","myDatabaseName","UserName","myPass
word") into myDB

... which works fine through a normal web connection, to this for the SSH
tunnel version...

put
revOpenDatabase("MySQL","localhost:PortNumberHere","myDatabaseName","UserNam
e","myPassword") into myDB

That doesn¹t work. I get the following error message.

³Can¹t connect to local MySQL server through socket Œtmp/mysql.sock¹ ²

I¹m using LiveCode 5.0.1 on Mac OSX. Is there a solution? Some other
parameter I need to specify? I have sqlite sitting in the same directory as
LiveCode. Could that be problematic? Thanks.

Sieg
_______________________________________________
use-livecode mailing list
use-li...@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Bob Sneidar

unread,
Dec 7, 2011, 6:21:14 PM12/7/11
to How to use LiveCode
Help says:
Syntax:
revOpenDatabase("mysql",host[:port], databaseName, [userName],[password],[useSSL], [socket], [timeout], [autoReconnect])

Notice the new useSSL argument? All you have to do now is determine if the host accepts SSL connections, and if so, on what port. I am not sure what you mean by an ssh tunnel. Are you talking about a VPN?

Bob


On Dec 7, 2011, at 2:08 PM, Sieg Lindstrom wrote:

> I have an app for managing data in a MySQL database on a remote server. It’s
> worked fine for years but now I would like to route the connection thru an
> SSH tunnel. It uses a port number other than 3306 (PortNumberHere in the
> function example below). So I’ve changed the relevant function from this...
>
> put
> revOpenDatabase("MySQL","madeuphost.com","myDatabaseName","UserName","myPass
> word") into myDB
>
> ... which works fine through a normal web connection, to this for the SSH
> tunnel version...
>
> put
> revOpenDatabase("MySQL","localhost:PortNumberHere","myDatabaseName","UserNam
> e","myPassword") into myDB
>
> That doesn’t work. I get the following error message.
>

> “Can’t connect to local MySQL server through socket ‘tmp/mysql.sock’ ”

Sieg Lindstrom

unread,
Dec 8, 2011, 4:37:26 PM12/8/11
to use-li...@lists.runrev.com
Thanks, Bob. I have to confess that I'm not well educated in networking. I'm
a regular guy who uses livecode to facilitate tasks I perform at work.

Here's a wikipedia article (yeah, know its limitations as a reference
source) that includes an explanation of SSH tunneling.

http://en.wikipedia.org/wiki/Tunneling_protocol

We're beefing up security on our server and I'm told my app will now need to
talk to the relevant MySQL database on the server thru this protocol,
assuming livecode is up to the task. Are SSH tunneling and VPN synonymous?
I'm not sure. The article above says this: "Tunneling protocols may use data
encryption to transport insecure payload protocols over a public network
(such as the Internet), thereby providing VPN functionality."

Thanks for the tip on the useSSL argument. If anyone has had direct
experience with livecode client apps and SSH tunneling, I'd appreciate any
insight.

Sieg


On 12/8/11 8:40 AM, Bob Sneidar wrote:

> Help says:
> Syntax:
> revOpenDatabase("mysql",host[:port], databaseName,
> [userName],[password],[useSSL], [socket], [timeout], [autoReconnect])
>
> Notice the new useSSL argument? All you have to do now is determine if the
> host accepts SSL connections, and if so, on what port. I am not sure what you
> mean by an ssh tunnel. Are you talking about a VPN?
>
> Bob

_______________________________________________

Admin

unread,
Dec 8, 2011, 5:29:16 PM12/8/11
to How to use LiveCode

In the past, when I was creating a php database and needed to test
it, but did not want to open the floodgates and allow any IP address in,
or if I was moving around from place to place

and my IP would change
depending on where I was, tunnelling was an option with some software.


Essentially, you have a small php app that you ftp to your server and
then the software you use 'talks' to that small program. You then have a
way to upload data to the server and test out

your database. It worked
like a charm.

I have since wrote a few programs with Live Code that
'talk' to a mySQL server and have not had any real problems, but I did
have to put my IP address in the server's cpanel so as to accept it.


(that was in the beginning - I figured out a more elegant solution -
see below). I believe you could write a small app in Live Code that you
could then upload to your server (say with a

username/password combo)
that would allow you to upload your work and changes like the one I used
for the php database. Of course, you could also just use .htaccess and
provide your

username/password whenever you needed to upload your
recent changes. No one else could then get in.

You can also use
.htaccess and then build the username/password into the Live Code app so
that the program itself can always gain entry, but no one else can login
without using the program.

This is what I am doing right now with Live
Code right now for database work.

Mike

On 08.12.2011 15:37, Sieg
Lindstrom wrote:

> Thanks, Bob. I have to confess that I'm not well
educated in networking. I'm
> a regular guy who uses livecode to
facilitate tasks I perform at work.
>
> Here's a wikipedia article
(yeah, know its limitations as a reference
> source) that includes an
explanation of SSH tunneling.
>
>

http://en.wikipedia.org/wiki/Tunneling_protocol [1]We're beefing up

> use-li...@lists.runrev.com [2]


> Please visit this url to
subscribe, unsubscribe and manage your subscription preferences:
>

http://lists.runrev.com/mailman/listinfo/use-livecode [3]


Links:
------
[1] http://en.wikipedia.org/wiki/Tunneling_protocol
[2]
mailto:use-li...@lists.runrev.com
[3]
http://lists.runrev.com/mailman/listinfo/use-livecode

Bernard Devlin

unread,
Dec 8, 2011, 6:02:45 PM12/8/11
to How to use LiveCode
Are you sure that your tunnel is working?

I'm assuming that for some reason SSL is not an option, neither is a VPN.
You should be able to tunnel a database connection through a SSH tunnel.
I've done it many times with different kinds of databases and servers
(although never with MySQL).

Can you provide the SSH command-line options you are using to create your
tunnel? As far as Livecode would be concerned, it would be connecting to a
MySQL server running on your local machine, so it's likely the problem lies
in the tunnel not being created. In fact, if you don't have MySQL
installed/running locally, then you should be able to just assign the
normal MySQL port to the local end of your tunnel (port 3306 is the default
I believe). That way you would obviate the need to change ports (so you'd
be specifying 3306 as the local end of your tunnel).

You could try using telnet to connect to localhost:3306 to see if there is
a response from MySQL through the tunnel (telnet localhost 3306). If you
do that before you have the tunnel created, then you'll find out if MySQL
is already running on your computer.

When you create your tunnel, you can make SSH give you wads of information,
by specifying the -v option (increase the verbosity by incrementing the
number of Vs e.g. -vvv).

If you can verify the tunnel is working using telnet, then it would seem to
be something peculiar to MySQL (or a local configuration problem with OS X).

Bernard

On Wed, Dec 7, 2011 at 10:08 PM, Sieg Lindstrom <s...@trackandfieldnews.com>wrote:

> That doesn¹t work. I get the following error message.
>
> ³Can¹t connect to local MySQL server through socket Œtmp/mysql.sock¹ ²
>
>

Reply all
Reply to author
Forward
0 new messages