Thursday, January 27, 2011

Re: Connecting to a remote database via SSH

Dave - I got a perfect solution to this a few days ago from Zaky Katalan-Ezra. My challenge wasn't connecting to a remote db via SSH using a client (I use Sequel Pro) as that works great. What I wanted to do was to create a database.php configuration that would allow a local Cake app to connect to the remote db, which means that all (distributed) developers can develop and test against a single database.

For good measure, here is Zaky's response:

edit /etc/ssh/sshd_config on your local machine
Add:
AllowTcpForwarding yes
GatewayPorts yes

restart sshd

Edit my.cnf on remote machine.
Uncomment the following line.
bind-address           = 127.0.0.1
restart mysql

On you local machine run the following command
ssh -i e-keypair -f remoteuser@remote.com -N -L 4444:localhost:3306
If you are not using ssh key you will be prompt for remote user assword

Edit database.php

var $default = array(
        'driver' => 'mysqli',
        'persistent' => false,
        'host' => '127.0.0.1',
        'port'=>4444,
        'login' => 'user',
        'password' => 'pass',
        'database' => 'schema',
        'prefix' => ''
);

On 27 Jan 2011, at 22:13, Dave Maharaj wrote:

I just setup mySQL workbench on my local machine to connect to my  server / sql database.
 I do not want phpmyAdmin so I use this to administer my db's.
 It connects thru the ssh tunnel. Is that what your looking for? I did not connect it to my localhost (my home machine) though so if that's what you are in need of I am unsure of that aspect but will follow this post to see if anyone else does.
 
Dave
 
From: Jeremy Burns [mailto:jeremyburns@classoutfit.com] 
Sent: Tuesday, January 25, 2011 4:02 PM
To: cake-php@googlegroups.com
Subject: Connecting to a remote database via SSH
 
Does anyone have any ideas for how to connect to a remote database via SSH? It's a development thing so that people working remotely can develop against the same database hosted on our virtual server.
-- 
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

-- 
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: